我正在尝试在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:
但是// usr / lib / x86_64-linux-gnu中确实存在libboost_thread.so.1.58.0。 谢谢大家。
答案 0 :(得分:0)
我再次进行了Boost 1.71的全新安装,突然CMake能够找到libboost-thread。我发现,CMake findpackage找不到带有boost 1.58(随apt-get安装)的libboost-thread,但是可以找到带有boost 1.71的libboost-thread。以前,我猜可能是因为boost 1.58没有完全删除,导致CMake无法找到boost-thread 1.71。此外,即使取消了Boost 1.51,CMake仍然可以在Ubuntu中找到Boost 1.48。