yarrr
yarrr

Reputation: 163

Undefined reference from shared library in static one

For example, I have 3 different instances:

  1. Shared library with undefined reference "get_object" and definition "x"
  2. Static library with definitions "get_object", "y".
  3. Binary file Object file with undefined references "x" and "y".

Am I right that linker can resolve all this symbols when I'll try to compile and link all this stuff together?

Main point of my worry is symbol "get_object". Can linker resolve such references between shared and static libraries?

Upvotes: 1

Views: 968

Answers (1)

Static libraries are just an agglomeration of object files (their members), perhaps with a ranlib(1) generated index.

On Linux, if you link an object file (3) foo.o with a static library (2) libee.a and a shared library (1) libyz.so and if you pass -rdynamic at link time (i.e. gcc -rdynamic foo.o libee.a libyz.so -o myprog or gcc -rdynamic foo.o -lee -lyz -o myprog) then dynamic linker would resolve the get_object name at dynamic link time (in ld-linux.so)

Details are explained in ELF wikipage and Drepper's paper: How To Write Shared Libraries. Read also Levine's book: Linkers and loaders & ld(1) man page.

Upvotes: 2

Related Questions