Reputation: 73
This question is one that has occurred before on SO. For instance this question: Cmake doesn't find Boost But the answers there and elsewhere don't seem to work.
On Ubuntu 16.04 with the stock boost 1.58.0 installed, I have also built, in a custom location, boost 1.68.0.
Now I am trying to compile a simple c++ program using boost, with cmake. It does not find boost. Either version (although 1.68.0 is the one I really want to use). It gives: -- Could NOT find Boost (missing: Boost_DIR)
The CMakeLists.txt file is below. CMake 3.12.1 is being used.
cmake_minimum_required(VERSION 3.0.0)
set(CMAKE_CXX_STANDARD 17)
project(mytest CXX)
set(Boost_DEBUG ON)
set(Boost_DETAILED_FAILURE_MSG ON)
set(BOOST_ROOT /home/hal/projects/boost/boost)
# set(Boost_DIR /home/hal/projects/boost/boost)
#set(Boost_USE_DEBUG_LIBS ON)
#set(Boost_USE_STATIC_LIBS ON)
#set(Boost_USE_MULTITHREADED ON)
# set(Boost_USE_STATIC_RUNTIME OFF)
#set(Boost_INCLUDE_DIR /home/hal/projects/boost/boost )
set(Boost_ADDITIONAL_VERSIONS "1.58" "1.58.0")
#set(BOOST_INCLUDEDIR /home/hal/projects/boost/boost/include )
#set(BOOST_LIBRARYDIR /home/hal/projects/boost/boost/lib )
#SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "/home/hal/projects/boost/boost")
#SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "/home/hal/projects/boost/boost/lib")
find_package(Boost 1.68.0 COMPONENTS system date_time PATHS /home/hal/projects/boost/boost )
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(mytest main.cpp)
target_link_libraries(mytest ${Boost_LIBRARIES} stdc++)
endif()
Upvotes: 0
Views: 862
Reputation: 66278
Unless you work with implementing of searching packaging, option PATHS for find_package
is not such useful, just remove it:
find_package(Boost 1.68.0 COMPONENTS system date_time)
There are two ways for search packages in CMake:
XXXConfig.cmake
script, shipped with a specific package installation. In this script all paths (libraries, include directories, etc.) are hardcoded.FindXXX.cmake
script, shipped with CMake itself. This script searches the libraries and headers under the system directories (like /usr/local/lib
) but also takes hints from the user.By default, the second way is tried; only if FindXXX.cmake
script is absent, the first way is used.
But some options for find_package
are applied only for the first way, and PATHS is exactly an option of this sort: it specifies paths where XXXConfig.cmake
file can be found. With such options, find_package
uses the second way - it tries to find XXXConfig.cmake
script and execute it. But it seems that your Boost installation lacks of this config script, so CMake fails to find Boost.
Upvotes: 1