简体   繁体   中英

Cmake can't find boost thread library

I am trying to use boost thread for my project in a Ubuntu machine. I download boost 1.58.0 via apt-get in ubuntu and use Cmake for building the c++ project.

In my CMakeLists.txt, I have

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} )

It turns out Cmake can't find the boost library

-- Boost_INCLUDE_DIR: /usr/include
-- Boost_LIBRARIES: 

I then checked online and figured out that I may need to specify the library, and changed the CMakeLists.txt to

find_package(Boost 1.58.0 COMPONENTS system filesystem thread REQUIRED)

But CMake can't find boost_thread. Here is the CMake output:

-- 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:

But libboost_thread.so.1.58.0 does exist in /usr/lib/x86_64-linux-gnu. Thank you all in advance.

I again did a fresh installation of boost 1.71, and suddenly CMake is able to find libboost-thread. What I found is that CMake findpackage can't find libboost-thread with boost 1.58 (installed with apt-get), but can find that with boost 1.71. Previously, I guess it's probably because boost 1.58 was not removed completely which causes CMake to fail to find boost-thread 1.71. Besides, even though boost 1.51 is removed, CMake can still find boost 1.48 in ubuntu.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM