-2

I'm trying to manipulate (or at least better understand) the symbol resolution order when loading dynamic libraries at runtime. In my example here I am using dlopen on a Linux OS.

I'm trying to get the dynamically loaded interpreter library "libmyint.so" to link with the function "message_from_library" in the shared object library "libmylib.so" and not with the "libmylib.a" that is linked into the application "myapp" which is what I currently have.

code.tar.gz

1 contains an archive of a simple example to understand this better. The following is the instructions on how to build the example and run it.

Instructions to build:

tar xzf code.tar.gz
mkdir app-build int-build lib-build
cd lib-build
cmake ../lib
make
cd ../int-build
cmake ../int
make
cd ../app-build
cmake ../app
make

./myapp

Actual output:

Call to statically linked interpreter function.
This message is from a static interpreter library object.
This message is from a static library object.
Call to dynamically loaded function in interpreter library.
This message is from a *shared* interpreter library object.
This message is from a static library object.

Desired output:

Call to statically linked interpreter function.
This message is from a static interpreter library object.
This message is from a static library object.
Call to dynamically loaded function in interpreter library.
This message is from a *shared* interpreter library object.
This message is from a *shared* library object.

I'm hoping someone can tell me how to get the desired output in this example.

Thanks.

  • Dup of: http://stackoverflow.com/questions/6292473/how-to-call-function-in-executable-from-my-library ? – ninjalj Jul 18 '14 at 11:14

1 Answers1

0

A dynamic library is used to resolve at runtime unresolved references. Anything that's already resolved at link time simply won't produce an unresolved reference. No matter what your dynamic linker tries, if there's no unresolved reference Foo then it can't resolve that at all.

MSalters
  • 173,980
  • 10
  • 155
  • 350