ld can't find shared boost library in cmake build in a docker container

275 Views Asked by At

I'm working on a cmake project which linked to boost libraries. I want to link to shared boost_unit_test_framework and static the others. A part of cmakelists.txt as below:

set(Boost_USE_STATIC_LIBS on)
add_definitions(-DBOOST_TEST_DYN_LINK)
find_package (Boost REQUIRED COMPONENTS timer system OPTIONAL_COMPONENTS chrono)
find_library(boost_test boost_unit_test_framework /opt/boost/lib)
set (TEST test-suite)
add_executable (${TEST} ${Test_SRC})
message(STATUS "##########################${boost_test}")
target_link_libraries (${TEST} ${boost_test})
target_link_libraries (${TEST} ${Boost_LIBRARIES})

I tried to build it in a docker container, link errors reported:

/usr/bin/ld: cannot find -lboost_unit_test_framework
collect2: error: ld returned 1 exit status
make[2]: *** [QuantLib/test-suite/CMakeFiles/quantlib-test-suite.dir/build.make:1574: QuantLib/test-suite/quantlib-test-suite] Error 1
make[1]: *** [CMakeFiles/Makefile2:1267: QuantLib/test-suite/CMakeFiles/quantlib-test-suite.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

Some information:
1.My cmake version is 3.11.4; boost version is 1.74, installed under /opt/boost.
2.If I build it on a linux server, there is no error; If I build it in a docker continer, errors emited. The docker continer has almose same settings with the linux server: centos8.1/cmake3.11/boost1.74
3.${boost_test} message in cmakelists.txt show a full path: /opt/boost/lib/libboost_unit_test_framework.so
4.Make a soft link to libboost_unit_test_framework.so under /usr/lib can fix the error, but I don't want to change the container environment. I want to fix it in CMake.
5.Shared libs: enter image description here

Any idea?

0

There are 0 best solutions below