构建和链接 Boost

Building and linking Boost

我正在尝试构建 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 运行 二进制 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 的新手,所以要温柔点;) 提前致谢

@usr1234567 感谢您的建议,之前从 CentOS 仓库使用 cmake 2.8。切换到 cmake 3.9,需要将 link 设置为位于 /usr/local/bin/cmake 中的默认二进制文件。还使用默认前缀构建了 boost。现在可以了。还更改了我的项目,例如 @Tsyvarev 建议不要覆盖 CMAKE_BINARY_DIR。稍后我会再次尝试使用前缀构建,但现在我很好。谢谢!