classa.h:
class A {
static const int kInt;
....
};
class B : public A {
void f(int p = A::kInt);
....
};
file classa.cpp:
#include "classa.h"
const int A::kInt = 0;
....
This file (classa.cpp) is included in a static library. This static
library is linked into a dynamic library (.dylib). The dynamic library
exports all globals. The dynamic library is included in an application
which uses b:f(). When linking the application I get an undefined
symbol error:
Link Error : undefined: 'A::kInt' (non lazy ptr IL)
A::kInt is used in other places, but the only undefined symbol errors
occur where it is being used as a default parameter value. I generated
a symbol map for the dynamic library and this symbol is listed like
this:
1435120 __literal4 __ZN1A4kIntE (merged entry exported from
classa.cpp)
Any thoughts? TIA!
Robert
What do you have for the dead strip static initializaion settings. Why
don't you put the
const int A::kInt = 0;
in the header file ?
Ron
--
Announcing CodeWarrior Development Tools for Windows v9.2
http://www.metrowerks.com/MW/Develop/Desktop/Windows/Professional/Default.htm
Ron Liechty - MW...@metrowerks.com - <http://www.metrowerks.com>
This was set on (in the static lib, dynamic lib and the application).
Turning them all off (no dead strip ..) did nothing.
> Why don't you put the
>
> const int A::kInt = 0;
>
> in the header file ?
This works (putting the initialization in the class definition) but we
would prefer not to have static initializers in header files.
What also works, since it is a constant and an integer type, is to
make it an enum:
class A {
enum { kInt = 0 };
Which requires no name changes anywhere else and solves the problem.
I have been told that using a static member as a parameter default
value is a bad idea if not illegal. On the other hand I still do not
understand why this became an undefined symbol. There are dark and
perilous places in the ways of dynamic library linking.
Thanks again.
Robert
Because a static by define is not exportable it only has local
translation unit linkage.
Ron
--
Free Download - New Version Released
CodeWarrior Development Studio for HC(S)12 Microcontrollers v3.1
offers "emulator-like" debugging support for HCS12 derivatives
http://www.metrowerks.com/MW/Develop/Embedded/HC12/Default.htm
> Because a static by define is not exportable it only has local
> translation unit linkage.
That's just wrong, Ron. The static keyword in C/C++ does not always mean that
the identifier it applies to does not have extern linkage. Static member
functions and static date members definitely do have extern linkage.
If it is indeed the case that having a static data member in a shared library
that exports all globals does not make that static data member available to
those who link against that library (and all indications are that that's
precisely what the OP's problem is), then that's a bug in the MW linker.
meeroh
--
If this message helped you, consider buying an item
from my wish list: <http://web.meeroh.org/wishlist>
To follow up on my original question. Does anyone know what "merged
entry exported from classa.cpp" means?
Robert
>In article <mwron-1FB036....@news.newsguy.com>,
> MW Ron <mw...@metrowerks.com> wrote:
>
>> Because a static by define is not exportable it only has local
>> translation unit linkage.
>
>That's just wrong, Ron. The static keyword in C/C++ does not always mean that
>the identifier it applies to does not have extern linkage. Static member
>functions and static date members definitely do have extern linkage.
Yes brain damage on my part, pure and simple March Madness
>If it is indeed the case that having a static data member in a shared library
>that exports all globals does not make that static data member available to
>those who link against that library (and all indications are that that's
>precisely what the OP's problem is), then that's a bug in the MW linker.
I don't know if it is or not, Now that you have me thinking right I
believe Bob sent me an example of something like this and how to set
these up correctly.
Robert if you want that send me a private mail.
>> I generated
>> a symbol map for the dynamic library and this symbol is listed like
>> this:
>>
>> 1435120 __literal4 __ZN1A4kIntE (merged entry exported from
>> classa.cpp)
>
>To follow up on my original question. Does anyone know what "merged
>entry exported from classa.cpp" means?
I'm told...
What ever value A::kInt is defined to have in classa.cpp is also used
someplace else so it merged the variables (by value since they were
constant), it prints the externally visible symbol. It is basicly the
same process used when merging functions "by value" (aka folding).