构建和链接 Boost



我正在尝试构建提升库并使用 cmake 构建我的应用程序。 构建和安装 boost 只是遵循入门指南并将前缀更改为/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
...

我的CMakeList.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)

当我运行时使一切正常,但是一旦我运行二进制文件,我就会收到以下错误....

./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,需要设置指向位于/usr/local/bin/cmake 中的二进制文件默认值的链接。还内置了带有默认前缀的提升。现在它起作用了。还更改了我的项目,就像@Tsyvarev建议不要覆盖CMAKE_BINARY_DIR一样。 以后我会再次尝试使用前缀构建,但现在我很好。谢谢!

最新更新