【发布时间】:2019-12-29 18:37:06
【问题描述】:
我正在尝试在 Ubuntu 机器上为我的项目使用 boost 线程。我在 ubuntu 中通过 apt-get 下载 boost 1.58.0 并使用 Cmake 构建 c++ 项目。
在我的 CMakeLists.txt 中,我有
find_package(Boost 1.58.0 REQUIRED)
include_directories( ${Boost_INCLUDE_DIR} )
message(STATUS "Boost_INCLUDE_DIR: ${Boost_INCLUDE_DIR}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
target_link_libraries( Sparse3D ${COLMAP_LIBRARIES} )
原来Cmake找不到boost库
-- Boost_INCLUDE_DIR: /usr/include
-- Boost_LIBRARIES:
然后我上网查了一下,发现我可能需要指定库,并将 CMakeLists.txt 更改为
find_package(Boost 1.58.0 COMPONENTS system filesystem thread REQUIRED)
但是 CMake 找不到 boost_thread。这是 CMake 输出:
-- Found Glew
-- Includes : /usr/include
-- Libraries : /usr/lib/x86_64-linux-gnu/libGLEW.so
-- __cplusplus is 201103
-- --> Do not link with Boost.Thread
-- Boost version: 1.58.0
-- Boost include dirs: /usr/include
-- Boost libraries:
CMake Error at /usr/share/cmake-3.5/Modules/FindBoost.cmake:1677 (message):
Unable to find the requested Boost libraries.
Boost version: 1.58.0
Boost include path: /usr/include
Could not find the following Boost libraries:
boost_thread
Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, set
BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.
Call Stack (most recent call first):
CMakeLists.txt:20 (find_package)
-- GLM_INCLUDE_DIR = /usr/local/include
-- GLM included at /usr/local/include
-- Boost_LIBRARIES: /usr/include
-- Boost_LIBRARIES:
但 libboost_thread.so.1.58.0 确实存在于 /usr/lib/x86_64-linux-gnu 中。 提前谢谢大家。
【问题讨论】:
-
感谢您的快速回复。我相信已经安装了Boost。我实际上卸载了1.58并安装了最新的稳定版本的boost,但问题仍然存在。
-
是的,已经安装了 libboost-all-dev 和 libboost-thread-dev。 libboost-all-dev 已经是最新版本(1.58.0.1ubuntu1)。 libboost-thread-dev 已经是最新版本(1.58.0.1ubuntu1)。
-
我再次全新安装了 boost 1.71,突然 CMake 能够找到 libboost-thread。我发现CMake findpackage 找不到带有boost 1.58 的libboost-thread(使用apt-get 安装),但可以找到带有boost 1.71 的libboost-thread。以前,我猜可能是因为 boost 1.58 没有完全删除,导致 cmake 找不到 boost-thread 1.71。此外,即使 boost 1.51 被移除,CMake 仍然可以在 ubuntu 中找到 boost 1.48。