Cmake cannot find Boost any longer

2019-06-11 07:03发布

Until yesterday, my program compiled and linked correctly. Since today, the same program (same source and same environment), does not link. The boost library is not found.

Top of CMakeLists.txt file:

...
find_package (Boost REQUIRED)
set (Boost_USE_STATIC_LIBS ON)
set (Boost_USE_MULTITHREADED OFF)
set (Boost_USE_STATIC_RUNTIME OFF)
find_package (Boost COMPONENTS program_options)

if (Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS})
endif()
...

Running cmake:

cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_DOCUMENTATION=ON ../NumberPuncher/
-- The C compiler identification is GNU 4.7.1
-- The CXX compiler identification is GNU 4.7.1
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Boost version: 1.49.0
-- Could NOT find Boost
-- Configuring done
-- Generating done
-- Build files have been written to: /SWEnvironment/sw/NumberPuncher_prj/Release

The line:

-- Boost version: 1.49.0

is wrong, since the Boost I have installed is 1.54.0. However, in the CMakeLists.txt file, the boost version is not specified and it does not need to be.

Building the program, I get link errors relative to Boost of this kind:

entrypoint.cpp:(.text.startup+0x6be): undefined reference to `boost::program_options::options_description::add_options()'

At first I thought the directory containing Boost had been removed, but it is still there.

I made a clean build, rerunning cmake, but the problem remains.

Any idea?

Environment:
Linux OpenSuse 12.2
GCC/G++ 4.7.1
Boost 1.54.0

1条回答
淡お忘
2楼-- · 2019-06-11 07:33

Moving the find_package(Boost COMPONENTS program_options) command where the find_package(Boost REQUIRED) was fixed the problem:

find_package (Boost COMPONENTS program_options)
set (Boost_USE_STATIC_LIBS ON)
set (Boost_USE_MULTITHREADED OFF)
set (Boost_USE_STATIC_RUNTIME OFF)

I still cannot understand why it has always worked in the past. If anybody could clarify that I would appreciate. Anyway now it should work in the future, too.

查看更多
登录 后发表回答