Hi everyone,
I have a linking error when using gcc4.2 and static member variables.
The class template definition is something around the following:
template<>
class Element<L2_t: public Element_common<L2, Side<2,2 {
public:
static const ubyte_t dim_ = 2;
static const ubyte_t num_nodes_ = 2;
static const ubyte_t gauss_pts_= 3;
// member functions
};
Undefined symbols:
"fea::Element<(fea::Element_type)1>::gauss_pts _", referenced from:
__ZN3fea7ElementILNS_12Element_typeE1EE10gauss_pts _E
$non_lazy_ptr in element.o
"fea::Element<(fea::Element_type)2>::gauss_pts _", referenced from:
__ZN3fea7ElementILNS_12Element_typeE2EE10gauss_pts _E
$non_lazy_ptr in element.o
"fea::Element<(fea::Element_type)3>::gauss_pts _", referenced from:
__ZN3fea7ElementILNS_12Element_typeE3EE10gauss_pts _E
$non_lazy_ptr in element.o
ld: symbol(s) not found
The strange thing is that I have many other static variables with the
same kind of definition (same type and const as you can see) but it
only complaints about the gauss_pts_ member variable. I solved the
problem by moving the definition to the cpp file as follows:
// in cpp file
const ubyte_t Element<L2_t>::gauss_pts_ = 3;
But I want to understand really what is happening here. When I compile
the code with gcc4.3, the problem disappears. So, is this a bug in the
compiler?
Thanks for the help,
aa 4 5754
aaragon wrote:
I have a linking error when using gcc4.2 and static member variables.
The class template definition is something around the following:
template<>
class Element<L2_t: public Element_common<L2, Side<2,2 {
public:
static const ubyte_t dim_ = 2;
static const ubyte_t num_nodes_ = 2;
static const ubyte_t gauss_pts_= 3;
WTH is 'ubyte_t'?
>
// member functions
};
Undefined symbols:
"fea::Element<(fea::Element_type)1>::gauss_pts _", referenced from:
__ZN3fea7ElementILNS_12Element_typeE1EE10gauss_pts _E
$non_lazy_ptr in element.o
"fea::Element<(fea::Element_type)2>::gauss_pts _", referenced from:
__ZN3fea7ElementILNS_12Element_typeE2EE10gauss_pts _E
$non_lazy_ptr in element.o
"fea::Element<(fea::Element_type)3>::gauss_pts _", referenced from:
__ZN3fea7ElementILNS_12Element_typeE3EE10gauss_pts _E
$non_lazy_ptr in element.o
ld: symbol(s) not found
The strange thing is that I have many other static variables with the
same kind of definition (same type and const as you can see) but it
only complaints about the gauss_pts_ member variable. I solved the
problem by moving the definition to the cpp file as follows:
// in cpp file
const ubyte_t Element<L2_t>::gauss_pts_ = 3;
But I want to understand really what is happening here.
Not much. Any static member variable/constant has to be defined if used
outside of the class. Since you didn't show us how those constants are
used, the assumption is that they *are* used outside and *must* be
defined or you're in violation of the ODR.
When I compile
the code with gcc4.3, the problem disappears. So, is this a bug in the
compiler?
Not from where I sit.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On Oct 20, 7:45*am, Victor Bazarov <v.Abaza...@comAcast.netwrote:
aaragon wrote:
I have a linking error when using gcc4.2 and static member variables.
The class template definition is something around the following:
* *template<>
* *class Element<L2_t: public Element_common<L2, Side<2,2 {
* *public:
* * * * * *static const ubyte_t dim_ = 2;
* * * * * *static const ubyte_t num_nodes_ = 2;
* * * * * *static const ubyte_t gauss_pts_= 3;
WTH is 'ubyte_t'?
just a type definition to cope with the way I name things.
>
* * * * // member functions
* * * * };
Undefined symbols:
* "fea::Element<(fea::Element_type)1>::gauss_pts _", referenced from:
* * * __ZN3fea7ElementILNS_12Element_typeE1EE10gauss_pts _E
$non_lazy_ptr in element.o
* "fea::Element<(fea::Element_type)2>::gauss_pts _", referenced from:
* * * __ZN3fea7ElementILNS_12Element_typeE2EE10gauss_pts _E
$non_lazy_ptr in element.o
* "fea::Element<(fea::Element_type)3>::gauss_pts _", referenced from:
* * * __ZN3fea7ElementILNS_12Element_typeE3EE10gauss_pts _E
$non_lazy_ptr in element.o
ld: symbol(s) not found
The strange thing is that I have many other static variables with the
same kind of definition (same type and const as you can see) but it
only complaints about the gauss_pts_ member variable. I solved the
problem by moving the definition to the cpp file as follows:
* * * * // in cpp file
* *const ubyte_t Element<L2_t>::gauss_pts_ = 3;
But I want to understand really what is happening here.
Not much. *Any static member variable/constant has to be defined if used
outside of the class. *Since you didn't show us how those constants are
used, the assumption is that they *are* used outside and *must* be
defined or you're in violation of the ODR.
It is defined, when inside a class you do something like
static const int test = 2;
you're defining inline the value of the constant. That is exacly what
I was doing before, but the linker couldn't find it. Weird thing is
that only happened with one varible, the other static constants were
defined in the same way, but they didn't give me problems. So there
must be a problem with the copmiler.
*When I compile
the code with gcc4.3, the problem disappears. So, is this a bug in the
compiler?
Not from where I sit.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
aaragon wrote:
On Oct 20, 7:45 am, Victor Bazarov <v.Abaza...@comAcast.netwrote:
>aaragon wrote:
>>I have a linking error when using gcc4.2 and static member variables. The class template definition is something around the following: template<> class Element<L2_t: public Element_common<L2, Side<2,2 { public: static const ubyte_t dim_ = 2; static const ubyte_t num_nodes_ = 2; static const ubyte_t gauss_pts_= 3;
WTH is 'ubyte_t'?
just a type definition to cope with the way I name things.
Well, the language prohibits initialisations of static const data
members *unless* they are of an *integral type*. If your 'ubyte_t' is
not integral, your code is ill-formed.
>> // member functions }; Undefined symbols: "fea::Element<(fea::Element_type)1>::gauss_pts _", referenced from: __ZN3fea7ElementILNS_12Element_typeE1EE10gauss_pts _E $non_lazy_ptr in element.o "fea::Element<(fea::Element_type)2>::gauss_pts _", referenced from: __ZN3fea7ElementILNS_12Element_typeE2EE10gauss_pts _E $non_lazy_ptr in element.o "fea::Element<(fea::Element_type)3>::gauss_pts _", referenced from: __ZN3fea7ElementILNS_12Element_typeE3EE10gauss_pts _E $non_lazy_ptr in element.o ld: symbol(s) not found The strange thing is that I have many other static variables with the same kind of definition (same type and const as you can see) but it only complaints about the gauss_pts_ member variable. I solved the problem by moving the definition to the cpp file as follows: // in cpp file const ubyte_t Element<L2_t>::gauss_pts_ = 3; But I want to understand really what is happening here.
Not much. Any static member variable/constant has to be defined if used outside of the class. Since you didn't show us how those constants are used, the assumption is that they *are* used outside and *must* be defined or you're in violation of the ODR.
It is defined, when inside a class you do something like
static const int test = 2;
you're defining inline the value of the constant.
Nope. It's declared and initialised. It's not defined. It's only
defined when you can say that the memory for it is allocated and *where*
it is allocated. Unless you do
const int <classname>::test;
in the *namespace* scope somewhere in a translation unit, the data
member is *undefined*.
That is exacly what
I was doing before, but the linker couldn't find it. Weird thing is
that only happened with one varible, the other static constants were
defined in the same way, but they didn't give me problems. So there
must be a problem with the copmiler.
Sure. What else could it be?.. Stupid compilers!
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On Oct 20, 2:38*pm, Victor Bazarov <v.Abaza...@comAcast.netwrote:
aaragon wrote:
On Oct 20, 7:45 am, Victor Bazarov <v.Abaza...@comAcast.netwrote:
aaragon wrote: I have a linking error when using gcc4.2 and static member variables. The class template definition is something around the following: * *template<> * *class Element<L2_t: public Element_common<L2, Side<2,2 { * *public: * * * * * *static const ubyte_t dim_ = 2; * * * * * *static const ubyte_t num_nodes_ = 2; * * * * * *static const ubyte_t gauss_pts_= 3;
WTH is 'ubyte_t'?
just a type definition to cope with the way I name things.
Well, the language prohibits initialisations of static const data
members *unless* they are of an *integral type*. *If your 'ubyte_t' is
not integral, your code is ill-formed.
u_byte is just a type definition for an unsigned short, which is of an
integral type. The rest of the static constant member variables were
also of the same type but only this one game the problem. Weird.
>
>* * * * // member functions * * * * }; Undefined symbols: * "fea::Element<(fea::Element_type)1>::gauss_pts _", referenced from: * * * __ZN3fea7ElementILNS_12Element_typeE1EE10gauss_pts _E $non_lazy_ptr in element.o * "fea::Element<(fea::Element_type)2>::gauss_pts _", referenced from: * * * __ZN3fea7ElementILNS_12Element_typeE2EE10gauss_pts _E $non_lazy_ptr in element.o * "fea::Element<(fea::Element_type)3>::gauss_pts _", referenced from: * * * __ZN3fea7ElementILNS_12Element_typeE3EE10gauss_pts _E $non_lazy_ptr in element.o ld: symbol(s) not found The strange thing is that I have many other static variables with the same kind of definition (same type and const as you can see) but it only complaints about the gauss_pts_ member variable. I solved the problem by moving the definition to the cpp file as follows: * * * * // in cpp file * *const ubyte_t Element<L2_t>::gauss_pts_ = 3; But I want to understand really what is happening here.
Not much. *Any static member variable/constant has to be defined if used
outside of the class. *Since you didn't show us how those constants are
used, the assumption is that they *are* used outside and *must* be
defined or you're in violation of the ODR.
It is defined, when inside a class you do something like
* *static const int test = 2;
you're defining inline the value of the constant.
Nope. *It's declared and initialised. *It's not defined. *It's only
defined when you can say that the memory for it is allocated and *where*
it is allocated. *Unless you do
* *const int <classname>::test;
in the *namespace* scope somewhere in a translation unit, the data
member is *undefined*.
*That is exacly what
I was doing before, but the linker couldn't find it. Weird thing is
that only happened with one varible, the other static constants were
defined in the same way, but they didn't give me problems. So there
must be a problem with the copmiler.
Sure. *What else could it be?.. *Stupid compilers!
Indeed, stupid compilers!
>
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Thanks for answering my post.
aa This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: IHateSuperman |
last post by:
public class StaticField2{
public static void main(String args){
private int x, y; // <<== error 1
for ( y = 0 ; y < 100 ; y++){
x = StaticMethod();
System.out.println(" x = "+x);
}
}
public...
|
by: James |
last post by:
Hello Java NG,
I not sure if this is the right NG for this type of question but if not
please let me know which is, TIA
Any way first off let me say I'm a student and this WAS last weeks lab,...
|
by: BCC |
last post by:
Hi,
I have a class with several member variables that should be initialized
according to user input before an object is instantiated. Using a static
variable is required here.
But, I would...
|
by: SM |
last post by:
Hi,
While linking orbix C++ application, we get a lot of linking errors.
Few errors are pasted below. If someone could tell us which are the
libraries that need to be added, it would be of help....
|
by: Daveyk0 |
last post by:
Hello there,
I have a front end database that I have recently made very many changes
to to allow off-line use. I keep copies of the databases on my hard
drive and link to them rather than the...
|
by: Sahil Malik [MVP] |
last post by:
So here's a rather simple question.
Say in an ASP.NET application, I wish to share common constants as static
variables in global.asax (I know there's web.config bla bla .. but lets just
say I...
|
by: Chris Stankevitz |
last post by:
At link time, MSVC determines some of my libraries are unused and doesn't
link them into my exe. This undesirable feature causes problems when I
employ the factory pattern. With the factory...
|
by: mangalalei |
last post by:
A static data member can be of the same class type as that of which it
is a member. A nonstatic data member is restricted to being declared as
a pointer or a reference to an object of its class.
...
|
by: Jaco Naude |
last post by:
Hi,
I'm using a static library in my application which links fine except
for a few global variables. The static library only contains a bunch
of .cpp and .h files and the global variables are...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |