2

cmake - 3.8

I compiled and installed boost libraries in /usr/local/lib/, but unable to make cmake detect boost program_options through the command find_package(Boost REQUIRED program_options). All other libraries find_package(Boost REQUIRED thread system) are found, and only adding program_options throws an error. I have tried quite a lot of things and kind of clueless - what is special about program_options.

-- Boost version: 1.63.0
-- Found the following Boost libraries:
--   filesystem
--   regex
--   serialization
--   unit_test_framework
--   iostreams
--   thread
--   system
--   chrono
--   date_time
--   atomic

The boost make was successful and it built the program_options library ( I can see it in the /usr/local/lib/ folder along with other boost libraries) . I just fail to understand, why would nt cmake find it?

Error : 
  Unable to find the requested Boost libraries.

  Boost version: 1.63.0

  Boost include path: /usr/local/include

  Could not find the following Boost libraries:

          boost_program_options

  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.

Directory structure

-rw-r--r-- 1 root root 1558464 Aug 12 15:46 /usr/local/lib/libboost_program_options.a
lrwxrwxrwx 1 root root      34 Aug 12 15:46 /usr/local/lib/libboost_program_options.so -> libboost_program_options.so.1.63.0*
-rwxr-xr-x 1 root root  658920 Aug 12 15:46 /usr/local/lib/libboost_program_options.so.1.63.0*
infoclogged
  • 3,641
  • 5
  • 32
  • 53

2 Answers2

1

I was able to solve this issue on Windows by adding set(Boost_DEBUG ON) set(Boost_USE_STATIC_LIBS ON) to my CMakeLists.txt file. This allowed CMake to find the correct version of boost and program_options.

My final CMakeList.txt looks something like this...

add_executable(test ${TEST_SRC})

set(Boost_USE_STATIC_LIBS ON)
find_package(Boost 1.30 COMPONENTS program_options REQUIRED)

if(Boost_FOUND)
    target_include_directories(test PRIVATE ${Boost_INCLUDE_DIRS})
    target_link_libraries(test ${Boost_LIBRARIES})
endif()
Alec Matthews
  • 31
  • 1
  • 6
-1

After hours and hours of debugging, I gave up and found a work around. maybe it will help someone. In case cmake is doing nasty things, but you are sure, that your library is there in the boost library folder - just link the library explicitly .

target_link_libraries(TARGET lib1 lib2 ${Boost_LIBRARIES} libboost_program_options.so)

You may have to add link_directories(/usr/local/lib/) beforehand, in case the rpath does not contain /usr/local/lib.

infoclogged
  • 3,641
  • 5
  • 32
  • 53