Operating System - HP-UX
1833883 Members
1610 Online
110063 Solutions
New Discussion

Global variables are not initialized in shared libraries

 
Grigori
Occasional Contributor

Global variables are not initialized in shared libraries

Hi all,

I have built a shared library with several global variables. Their constructors are not called when the library is loaded. Where the problem may be? The same code work perfectly on Linux.
Compiler is GCC 3.2.2. Linker command line options are "g++ -Wl,s -fPIC -shared -Wl,-b ...".

Thanks in advance for any help...
4 REPLIES 4
ranganath ramachandra
Esteemed Contributor

Re: Global variables are not initialized in shared libraries

i think you need to include libstd++.sl in the link line (if its not already being included by g++). what does the actual link line (as can be seen with g++ -v option) look like ?

whats -Wl,s ? i guess you meant -Wl,+s or -Wl,-s.
 
--
ranga
hp-ux 11i v3[i work for hpe]

Accept or Kudo

Grigori
Occasional Contributor

Re: Global variables are not initialized in shared libraries

Here is the g++ output:

Reading specs from /usr/local/lib/gcc-lib/hppa2.0w-hp-hpux11.00/3.2.2/specs
Configured with: ./configure : (reconfigured) ./configure : (reconfigured) ./configure --enable-threads=posix : (reconfigured) ./configure --enable-threads=posix : (reconfigured) ./configure --with-gnu-as --enable-threads=posix : (reconfigured) ./configure --with-gnu-as --enable-threads=posix : (reconfigured) ./configure --with-gnu-as --enable-threads=posix --enable-shared : (reconfigured) ./configure --with-gnu-as --enable-threads=pthreads --enable-shared : (reconfigured) ./configure --with-gnu-as --enable-threads=posix --enable-shared : (reconfigured) ./configure --with-gnu-as --enable-threads=posix : (reconfigured) ./configure --with-gnu-as --enable-threads=posix : (reconfigured) ./configure --with-gnu-as --enable-threads=posix : (reconfigured) ./configure : (reconfigured) ./configure --with-gnu-as --enable-threads=posix
Thread model: posix
gcc version 3.2.2
/usr/local/lib/gcc-lib/hppa2.0w-hp-hpux11.00/3.2.2/collect2 -z -b -o lib.so.0.1.0 -L/usr/local/lib/gcc-lib/hppa2.0w-hp-hpux11.00/3.2.2 -L/usr/ccs/bin -L/usr/ccs/lib -L/usr/local/lib/gcc-lib/hppa2.0w-hp-hpux11.00/3.2.2/../../.. -s -b +h lib.so.0.1 obj.o -lpthread -lstdc++ -lm -lgcc_s -lgcc_s
ranganath ramachandra
Esteemed Contributor

Re: Global variables are not initialized in shared libraries

i dont seem to have access to an installation of gcc hppa-2.0w rightaway. this seems to work with gcc 3.2 hppa-2.0n. i'll try to get more info on this.

by the way, what makes you choose hppa2.0w over hppa2.0n, since both build only 32bit objects?
 
--
ranga
hp-ux 11i v3[i work for hpe]

Accept or Kudo

Grigori
Occasional Contributor

Re: Global variables are not initialized in shared libraries

I'm sorry, I'm not an expert in this field. GCC was configured and built from sources on that machine. How can I switch between hppa2.0w and hppa2.0n?
And what will be the difference between them?