首页 > 解决方案 > Cmake找不到boost线程库

问题描述

我正在尝试在 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 中。谢谢大家。

标签: c++boostcmake

解决方案


我再次重新安装了 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。


推荐阅读