CMake,链接目录和多个Boost安装

时间:2014-11-28 16:07:03

标签: c++ boost cmake

我正在使用没有root权限的服务器。我有一个简单的命令行应用程序,链接到OpenCV和Boost,我使用的是cmake 2.8.12。 / usr / lib64中有旧的boost库,但我想使用更新的boost库,我可以使用环境模块加载它们。 CMakeLists.txt文件如下:

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} )

消息打印到正确库的完整路径:

  

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

     

提升图书馆   /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

链接时出现问题,cmake生成以下对c ++的调用:

  

/ 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

请注意如何去除boost库的绝对路径,并且不使用-L标志包含它。然后我得到以下警告,暗示链接器正在接收/ usr / lib64中另一个较旧的boost安装

  

/ usr / bin / ld:警告:libboost_system.so.1.56.0,需要   /cm/shared/apps/boost/1.56/lib/libboost_thread.so,可能与   libboost_system.so.5

然后链接会因为一长串错误而失败,可能是因为使用了旧的Boost库,但代码是使用较新的Boost头构建的。

如果我将以下内容添加到CMakeLists.txt:

  

设置(CMAKE_CXX_FLAGS“$ {CMAKE_CXX_FLAGS} -L $ {Boost_LIBRARY_DIRS}”)

然后代码链接没有问题。我花了一些时间研究,但到目前为止,我已经画了一个空白,如何让CMake包含-L标志或如何阻止它从boost库中剥离绝对路径。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

我相信documentationset(Boost_REALPATH ON)中解释了这一点。

  

Boost_REALPATH - 设置为ON以解析已发现的符号链接                                图书馆协助包装。例如,                                可以解析“系统”组件库                                “/usr/lib/libboost_system.so.1.42.0”而不是                                “/usr/lib/libboost_system.so”。事实并非如此                                影响链接,除非是,否则不应启用                                用户需要此信息。