构建和链接Boost

时间:2017-08-09 14:30:52

标签: c++11 boost cmake centos7

我试图构建boost库并使用cmake来构建我的应用程序。 构建和安装boost只需遵循Getting Started Guide并将前缀更改为/ usr

./bootstrap.sh --prefix=/usr
./b2 install

结果我现在在/ usr / lib:

libboost_atomic.a
libboost_atomic.so
libboost_atomic.so.1.64.0
...

在/ usr / include / boost

aligned_storage.hpp
align.hpp
...

我的CMakeLists.txt

cmake_minimum_required (VERSION 2.6)
project (NewMediaServer)
# Set the output folder where your program will be created
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})    
# set the folder of the binarys
include_directories(${PROJECT_BINARY_DIR}/src)
# find all packages which we are depending on
find_package(Boost 1.64 REQUIRED)
# name the main cpp and the executable
add_executable(mediaserver src/MediaServer.cpp)
# configure compile and linking options
target_compile_options(mediaserver PUBLIC -std=c++11 -Wall)
target_link_libraries(mediaserver PUBLIC -pthread -lboost_system -lboost_log -lboost_log_setup -lboost_thread -lboost_date_time -lboost_filesystem)

当我运行时,一切正常,但是一旦运行二进制iam得到以下错误....

./bin/mediaserver: error while loading shared libraries: libboost_system.so.1.64.0: cannot open shared object file: No such file or directory

真的很感激任何帮助!我仍然是Cmake和Boost的新手,所以要温柔;) 提前致谢

1 个答案:

答案 0 :(得分:0)

@ usr1234567感谢您的建议,之前在CentOS repo中使用过cmake 2.8。切换到cmake 3.9,需要设置指向/ usr / local / bin / cmake中二进制文件默认值的链接。还使用默认前缀构建了boost。现在它有效。还改变了我的项目,如@Tsyvarev建议不要覆盖CMAKE_BINARY_DIR。任何时候以后我会再次尝试使用前缀构建,但现在我很好。谢谢!