3

Im trying to use the program_options library from Boost. However, CMake can and can't find boost... What am I doing wrong?

CMakeLists.txt:

cmake_minimum_required (VERSION 3.8)
project(myProject)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "-std=c++0x -g -Wall -O3")

set(CMAKE_CXX_FLAGS_DEBUG "-g")

include_directories ("${PROJECT_BINARY_DIR}")

SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "~/Documents/test/myProject/lib/boost_1_65_0")
SET(CMAKE_BOOST_ROOT ${CMAKE_BOOST_ROOT} "~/Documents/test/myProject/lib/boost_1_65_0")
#SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "lib/boost_1_65_0/stage/lib")
include_directories(lib/boost_1_65_0/boost)

FIND_PACKAGE(Boost 1.65.0 COMPONENTS program_options )  
MESSAGE(${Boost_INCLUDE_DIR})

INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})

add_executable (myProject main.cpp)


TARGET_LINK_LIBRARIES( myProject LINK_PUBLIC ${Boost_LIBRARIES} -static-libgcc -static-libstdc++ pthread  )

FIND_PACKAGE returns:
-- Could NOT find Boost
But MESSAGE(${Boost_INCLUDE_DIR}) returns a directory..

Building fails nevertheless. As you can see hopefully, I have tried to follow the answer to this related question: undefined reference to `boost::program_options::options_description::m_default_line_length' but did not solve the problem.

I'm on Ubuntu 16.04 with cmake 3.11 and boost located in lib/boost_1_65_0

Edit: adding the line set(Boost_DEBUG ON) before find_package() as suggest by Tsyvarev returns the following output:

-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1121 ] _boost_TEST_VERSIONS = 1.67.0;1.67;1.66.0;1.66;1.65.1;1.65.0;1.65
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1123 ] Boost_USE_MULTITHREADED = TRUE
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1125 ] Boost_USE_STATIC_LIBS = 
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1127 ] Boost_USE_STATIC_RUNTIME = 
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1129 ] Boost_ADDITIONAL_VERSIONS = 
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1131 ] Boost_NO_SYSTEM_PATHS = 
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1199 ] Declared as CMake or Environmental Variables:
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1201 ]   BOOST_ROOT = 
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1203 ]   BOOST_INCLUDEDIR = 
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1205 ]   BOOST_LIBRARYDIR = 
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1207 ] _boost_TEST_VERSIONS = 1.67.0;1.67;1.66.0;1.66;1.65.1;1.65.0;1.65
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1306 ] location of version.hpp: /home/me/Documents/test/myProject/lib/boost_1_65_0/boost/version.hpp
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1330 ] version.hpp reveals boost 1.65.0
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1416 ] guessed _boost_COMPILER = -gcc54
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1426 ] _boost_MULTITHREADED = -mt
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1502 ] _boost_RELEASE_ABI_TAG = -
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1504 ] _boost_DEBUG_ABI_TAG = -d
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1567 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = /home/me/Documents/test/myProject/lib/boost_1_65_0/lib;/home/me/Documents/test/myProject/lib/boost_1_65_0/../lib;/home/me/Documents/test/myProject/lib/boost_1_65_0/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib_boost_LIBRARY_SEARCH_DIRS_DEBUG   = /home/me/Documents/test/myProject/lib/boost_1_65_0/lib;/home/me/Documents/test/myProject/lib/boost_1_65_0/../lib;/home/me/Documents/test/myProject/lib/boost_1_65_0/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1756 ] Searching for PROGRAM_OPTIONS_LIBRARY_RELEASE: boost_program_options-gcc54-mt-1_65;boost_program_options-gcc54-mt;boost_program_options-mt-1_65;boost_program_options-mt;boost_program_options
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1809 ] Searching for PROGRAM_OPTIONS_LIBRARY_DEBUG: boost_program_options-gcc54-mt-d-1_65;boost_program_options-gcc54-mt-d;boost_program_options-mt-d-1_65;boost_program_options-mt-d;boost_program_options-mt;boost_program_options
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1883 ] Boost_FOUND = 1
-- Could NOT find Boost
Boost version: 1.65.0
Boost include path: /home/me/Documents/test/myProject/lib/boost_1_65_0
Could not find the following Boost libraries:
        boost_program_options
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.
/home/me/Documents/test/myProject/lib/boost_1_65_0
2
  • 4
    Aside from words Could NOT find Boost there should be others describing the problem. Also, in case of problems in finding Boost, the first step could be enabling Boost_DEBUG: Add line set(Boost_DEBUG ON) before find_package() call and show resulted log.
    – Tsyvarev
    Commented Apr 6, 2018 at 8:32
  • 1
    Btw, instead of setting -std=c++0x you can set C++ standard by using a target property: cmake.org/cmake/help/v3.1/prop_tgt/CXX_STANDARD.html Commented Apr 6, 2018 at 10:03

3 Answers 3

4

You need to install the libraries not only the headers.

sudo apt install libboost-program-options-dev 

should fix your problem.

1
  • I get 0 upgraded, 0 newly installed, 0 to remove and 86 not upgraded. cmake still can't find boost.
    – Ant
    Commented Oct 19, 2022 at 20:46
0

It seems like CMake/FindBoost could not find the library file for Boost.ProgramOptions. Verify the names you show in the output actually exist somewhere on your system, and if so, ensure FindBoost is looking there.

0

It is working now, I think building boost solved the problem:

./bootstrap.sh --prefix=path where to install
./b2 install

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.