CMake, link directories and multiple Boost installations

I am working on a server without root privileges. I have a simple command line application that links to OpenCV and Boost and I am using cmake 2.8.12. There are old boost libraries in / usr / lib 64, but I want to use newer boost libraries that I can load using the environment module. The CMakeLists.txt file is as follows:

cmake_minimum_required(VERSION 2.8.12)

find_package(Boost 1.55.0 REQUIRED COMPONENTS program_options system thread)
find_package(OpenCV REQUIRED)

message("Boost dirs: ${Boost_LIBRARY_DIRS} ${Boost_INCLUDE_DIRS}")
message("Boost libraries ${Boost_LIBRARIES}")

include_directories(${OpenCV_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})

# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${Boost_LIBRARY_DIRS}")

add_executable(tile_images src/tile_images.cpp)
target_link_libraries(tile_images ${OpenCV_LIBRARIES} ${Boost_LIBRARIES} )

      

Messages print full paths to the required libraries:

Boost dirs: /cm/shared/apps/boost/1.56/lib / cm / shared / apps / boost / 1.56 / include

Boost libraries / cm / shared / apps / boost / 1.56 / lib / libboost_program_options.so; /cm/shared/apps/boost/1.56/lib/libboost_system.so; /cm/shared/apps/boost/1.56/lib/libboost_thread .so

The problem comes when linking, cmake generates the following C ++ call:

/ usr / bin / C ++ CMakeFiles / tile_images.dir / src / tile_images.cpp.o -o tile_images -rdynamic / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_videostab.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_video.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_ts.a / cm / shared / apps / opencv / 2.4.9 /lib/libopencv_superres.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_stitching.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_photo.so .2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_ocl.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_objdetect.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_nonfree.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_ml.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_legacy.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_imgproc.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib /libopencv_highgui.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_gpu.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_flann.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_features2d.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_core.so.2.4.9 / cm / shared / apps / opencv / 2.4. 9 / lib / libopencv_contrib.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_calib3d.so.2.4.9 -lboost_program_options -lboost_system -lboost_thread -ldl -lm -lpthread -lrt / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_nonfree.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_ocl.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_gpu.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_photo.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_objdetect.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_legacy.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_video.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_ml.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_calib3d.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_features2d.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_highgui.so.2.4.9 / cm / shared / apps / opencv / 2.4. 9 / lib / libopencv_imgproc.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_flann.so.2.4.9 / cm / shared / apps / opencv / 2.4.9 / lib / libopencv_core. so.2.4.9

Note that the absolute path to the acceleration libraries has been removed and is not enabled using the -L flag. I then get the following warning, hinting that the linker is picking up a different, older push install to / usr / lib 64

/ usr / bin / ld: warning: libboost_system.so.1.56.0 required for / cm / shared / apps / boost / 1.56 / lib / libboost_thread.so may conflict with libboost_system.so.5

Linking comes with a long list of errors, possibly because old Boost libraries are used, but the code is built with new Boost headers.

If I add the following to CMakeLists.txt:

set (CMAKE_CXX_FLAGS "$ {CMAKE_CXX_FLAGS} -L $ {Boost_LIBRARY_DIRS}")

then code links without issue. I've spent some time researching, but so far I've drawn a blank on how to get CMake to enable the -L flag or how to stop it from removing absolute paths from the boost libraries. Any help would be much appreciated!

+3


source to share


1 answer


I believe that this is explained in the documentation : set(Boost_REALPATH ON)

.



Boost_REALPATH - Set to ON to enable symbolic links for detected libraries to assist with packaging. For example, the "systems" component library might be allowed "/usr/lib/libboost_system.so.1.42.0" instead of "/usr/lib/libboost_system.so". It does not affect communication and should not be enabled if the user needs this information.

0


source







All Articles