Reputation: 378
I have an issue with global variables in shared library on Solaris. Consider following sample:
class Foo
{
public:
Foo() { Init(); }
private:
void Init() { // do something }
};
I have some code in shared library:
Foo g_Foo;
I've noticed that Foo constructor is never called on Solaris while the same code works Linux.
I'm using gcc 3.4.3 and Sun linker.
Upvotes: 0
Views: 606
Reputation: 822
Are you creating the shared object with the -G flag? e.g. CC -G -o mylib.so myfile.cpp
If you don't specify -G, then the compiler may not initialise global variables correctly. See compiler documentation here.
Note, the docs also say you can't use ld, but need to use CC to do the linking.
Upvotes: 1