Ramakrishnan Kannan
Ramakrishnan Kannan

Reputation: 624

linking with particular version of a library

I am linking boost libraries with my .cpp files. The build machine has boost 1.55 in /usr/lib64 and I have boost 1.57 in my local directory. The cmake generates the following link command.

/home/ramki/mpich-install/bin/mpicxx -fopenmp -fexceptions -fno-use-linker-plugin CMakeFiles/factor.dir/factor.cpp.o CMakeFiles/factor.dir/factor_jobs.cpp.o -o factor -rdynamic -lboost_serialization -lboost_iostreams -lboost_program_options -lboost_mpi -llapack -llapacke -lblas -lpthread -lm -lz factorization/libfactorization.a

The above link command does not specify the version of the boost libraries. Because of this I get the following error.

/usr/bin/ld: warning: libboost_serialization.so.1.57.0, needed by /home/ramki/libraries/boost_1_57_0//lib/libboost_mpi.so, may conflict with libboost_serialization.so.1.55.0

Because of this nature of linking, when I use ldd to dump the linked libraries of the executable, I see it linked with couple of libboost 1.55 libraries. If the machine in which I run this executable does not have boost 1.55, it does not start at all.

In the CMakeLists.txt and CMakeCache.txt, I see that the find_package is discovering the 1.57 libraries.

find_package(Boost 1.57.0 COMPONENTS serialization iostreams program_options mpi REQUIRED).

However during linking it is not introducing the version of the library. How do I instruct the cmake to do the following.

  1. linking libraries to use a particular version. For eg., -l:libboost_mpi.so.1.57.0
  2. specify the library path for this version -L library path explicitly. It should NOT link with the library under /usr/lib64.

Ramki

Upvotes: 0

Views: 1427

Answers (1)

Ramakrishnan Kannan
Ramakrishnan Kannan

Reputation: 624

Not sure if this will work for other libraries. Atleast for boost before find_package on boost, set (Boost_REALPATH ON). This will set Boost_LIBRARIES with full path as /export5/home/ramki/libraries/boost_1_57_0/lib/libboost_serialization.so.1.57.0;/export5/home/ramki/libraries/boost_1_57_0/lib/libboost_iostreams.so.1.57.0;/export5/home/ramki/libraries/boost_1_57_0/lib/libboost_program_options.so.1.57.0;/export5/home/ramki/libraries/boost_1_57_0/lib/libboost_mpi.so.1.57.0.

Use this Boost_LIBRARIES with target_link_libraries(theTarget ${Boost_LIBRARIES}). Thus instead of linking with libboost_mpi.so that could be link to other versions, we are linking with the library of the correct version.

Upvotes: 1

Related Questions