Cannot find boost with CMake on Linux Mint

2019-08-03 03:32发布

问题:

I have been working on a library in C++ and have run into a bit of difficulty trying to integrate boost into my project. I kept the message that boost could not be found, but on the other hand, my fellow developer using Arch had no issues.

We figured out that this is because Linux Mint (at least with the libboost-all-dev package) installs the libraries to /usr/lib/x86_64-linux-gnu which is not searched by the FindBoost module. We fixed this by creating symbolic links:

ln -s /usr/lib/x86_64-linux-gnu/libboost* /usr/lib/

What I want to know: is there a better (more acceptable) way of fixing this because when I compile major projects, I do not run into this problem.

Here is CMakeLists.txt (with some omissions)

cmake_minimum_required(VERSION 2.8)
project(testlibrary CXX)

set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)

find_package(Boost 1.55.0 COMPONENTS unit_test_framework thread log REQUIRED)

include_directories(${Boost_INCLUDE_DIRS})

add_library(testlibrary STATIC ${SOURCE_MAIN})

target_link_libraries(testlibrary ${Boost_LIBRARIES})

回答1:

You can set the hint BOOST_LIBRARYDIR:

set(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu")
find_package(Boost 1.55.0 COMPONENTS unit_test_framework thread log REQUIRED)

Alternative, you can set this when running CMake like this:

cmake -DBOOST_LIBRARYDIR="/usr/lib/x86_64-linux-gnu" <project_root>

If you just run:

cmake <project_root>

then FindBoost.cmake will look in the usual spots for your boost libaries.

See the documentation of FindBoost.cmake for your CMake version here.