tags:

views:

75

answers:

1

Under gcc (g++), I have compiled a static .a (call it some_static_lib.a) library. I want to link (is that the right phrase?) this .a file into another dynamic library (call it libsomeDyn.so) that I'm building. Though the .so compiles, I don't see content of .a under .so using nm command:

/usr/bin/g++ -fPIC -g -O2 -Wall -Werror -pipe -march=pentium3 -mtune=prescott -MD -D_FILE_OFFSET_BITS=64 -DLINUX -D_GNU_SOURCE -D_THREAD_SAFE -I../../../../../../../../ -I../../../../../../../..//libraries -Wl,-rpath,/usr/lib -o libsomeDyn.so some.o another.o some_static_lib.a -shared -Wl -x -Wl,-soname,libsomeDyn.so

I do not see functions under some_static_lib.a under libsomeDyn.so. What am I doing wrong?

+2  A: 

Static libraries have special rules when it comes to linking. An object from the static library will only added to the binary if the object provides an unresolved symbol.

On Linux, you can change that behavior with the --whole-archive linker option:

g++ -Wl,--whole-archive some_static_lib.a -Wl,--no-whole-archive
R Samuel Klatchko
So I have some weird dependency in the static library. It references a function included in the dynamic library. How do I tell gcc to find the undefined reference inside the dynamic library?Thanks
bob
@bob - there should be no problem with the static library referencing a symbol within the dynamic library (once you link a static library, it's just the same as if you directly referenced the .o on the command line). I suspect there must be some other problem and recommend posting a new question.
R Samuel Klatchko