I have a project in C++ which currently is not linked against any external dynamic library. I'm thinking about using some of boost libraries in future which need to be built (not header-only). For now, in the stage of development, I build my project with three different tool chains: g++
, LLVM/Clang++
and Intel C++
, the platform is Linux
. These compilers, AFAIK, are binary compatible with each other, e.g. g++-compiled app can use Intel C++-compiled dynamic library.
I've built boost binaries and installed them into different folders. e.g. build_gcc
, build_icc
. Then I added paths to these folders to the system LIBRARY_PATH
. The question is: if I now build my project with either g++
or Intel C++
and link some dynamic library, e.g. write
-lboost_math_tr1
in the makefile
, how does the linker decide which exact library file to link against if the binaries from different compilers are compatible with each other?
The motivation of the question is simple: Intel C++
is an optimizing compiler, so if I build things with it, I expect them to be linked against dynamic library compiled with Intel C++
compiler, not against the one compiled with g++
. Of course, I know that I can simply use multiple conditional statements in the makefile
to set the exact directories with library binaries for each used tool chain but it is just a bit inconvenient. I am wandering, is the linker smart enough to recognize which exact shared library file it should use or does it simply use the first occurrence found in the system LIBRARY_PATH
?