Static linkage in shared object

Hi all, Using Linux and g++, is it possible to create a shared object that statically links to Boost.Thread (1.33.1)? I'm doing something like: g++ -static -pthread -lboost_thread-gcc-mt -shared -o <name>.so <sourcefiles> to create a shared object (it's a JNI library written in C++). It compiles fine, but when I use it from Java I always getting an exception stating that libboost_thread-gcc-mt-1_33_1.so.1.33.1 cannot be found - but that's intentional, I haven't put /usr/local/lib in LD_LIBRARY_PATH because I don't want to dynamically link. Any help greatly appreciated!

Graham Bull wrote:
It compiles fine, but when I use it from Java I always getting an exception stating that libboost_thread-gcc-mt-1_33_1.so.1.33.1 cannot be found - but that's intentional, I haven't put /usr/local/lib in LD_LIBRARY_PATH because I don't want to dynamically link.
Right: looks like you've linked to the usual Boost.Thread shared library, probably the easiest solution to force linkage to the static version is to explicitly add the name of the static Boost.Thread lib on the command line rather than the usual -lboost_thread. HTH, John.

Graham Bull wrote:
Hi all,
Using Linux and g++, is it possible to create a shared object that statically links to Boost.Thread (1.33.1)?
I'm doing something like:
g++ -static -pthread -lboost_thread-gcc-mt -shared -o <name>.so <sourcefiles>
to create a shared object (it's a JNI library written in C++).
It compiles fine, but when I use it from Java I always getting an exception stating that libboost_thread-gcc-mt-1_33_1.so.1.33.1 cannot be found - but that's intentional, I haven't put /usr/local/lib in LD_LIBRARY_PATH because I don't want to dynamically link.
Any help greatly appreciated!
Please read the docs of the -static and -shared options -- they don't do what you seem to think. Then, read up on linker options -Bstatic and -Bshared (which can be passed on gcc command line as -Wl,-Bstatic and -Wl,-Bshared). - Volodya
participants (3)
-
Graham Bull
-
John Maddock
-
Vladimir Prus