直到昨天,我的程序正确编译和链接。从今天开始,相同的程序(相同的源和相同的环境),不链接。未找到 boost 库。
CMakeLists.txt 文件的顶部:
...
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()
...
运行 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
该行:
-- 增强版:1.49.0
错了,因为我安装的Boost是1.54.0。但是,在 CMakeLists.txt 文件中,没有指定 boost 版本,也不需要。
构建程序时,我得到与此类 Boost 相关的链接错误:
entrypoint.cpp:(.text.startup+0x6be): undefined reference to `boost::program_options::options_description::add_options()'
起初我以为包含 Boost 的目录已被删除,但它仍然存在。
我做了一个干净的构建,重新运行 cmake,但问题仍然存在。
任何想法?
环境:
Linux OpenSuse 12.2
GCC/G++ 4.7.1
Boost 1.54.0