c++ - Solaris shared libraries and global variables -


I have a problem with the global variable in the shared library on Solaris, consider the following sample:

  square fu {public: fu () {init (); } Private: Zero Init () {// do something}};   

I have some code in the shared library:

  foo j_fu;   

I have seen that the FU constructor is never called on Solaris, while the same code linux works.

I am using gcc 3.4.3 and Sun linker.

Are you composing the shared object with the -g flag? Like CC-GO Mylib.So MyFile CPP

If you do not specify -G, then the compiler can not start the global variable properly. See compiler documentation.

Note, the document also says that you can not use LD, but need to use CC to link.

Comments