Consider the following scenario:
- The libA.so shared library without dependencies.
- The shared library is libB.so, with libA.so as its dependency.
I want to compile a binary file that links to libB. Should I link the binary to libB only or to libA either?
Is there a way to associate only with direct dependencies by allowing the resolution of unresolved characters from dependencies for the runtime?
My concern is that the implementation of the libB library may change in the future by introducing other dependencies (libC, libD, libE, for example). Will I have problems with this?
In other words:
- LibA files: a.cpp ah
- Libb files: b.cpp bh
- main program files: main.cpp
Of course, b.cpp includes ah and main.cpp includes bh
Compilation Commands:
g++ -fPIC a.cpp -c g++ -shared -o libA.so ao g++ -fPIC b.cpp -c -I. g++ -shared -o libB.so bo -L. -lA
Which of the following options should I use?
g++ main.cpp -o main -I. -L. -lB
or
g++ main.cpp -o main -I. -L. -lB -lA
I could not use the first option. The compiler complains about unresolved characters from the libA library. But that sounds a little strange to me.
Thank you very much.
- Updated comments:
When I link the binary, the linker will try to resolve all characters from the main and libB. However, libB has undefined characters from libA. This is why the linker complains about this.
This is why I need to link to libA too. However, I found a way to ignore unresolved characters from shared libraries. It looks like I should use the following command line for this:
g++ main.cpp -o main -I. -L. -lB -Wl,-unresolved-symbols=ignore-in-shared-libs
It looks like you can still use the -rpath option. However, I need to understand this a little better.
Does anyone know of any possible errors when using the -Wl,-unresolved-symbols=ignore-in-shared-libs option?
- Updated comments 2:
-rpath should not be used for this purpose. It is useful to make the library find in this directory. The -unresolved-symbol approach looks much better.
Thanks again.
gcc dll g ++ dependencies
Marcus Jun 15 '12 at 17:34 2012-06-15 17:34
source share