直到昨天,我的程序已正确编译和链接。从今天开始,相同的程序(相同的源和相同的环境),不链接。找不到增强库。
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
该行:
- Boost版本: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
提升1.54.0
答案 0 :(得分:0)
移动find_package(Boost COMPONENTS program_options)
命令解决find_package(Boost REQUIRED)
问题:
find_package (Boost COMPONENTS program_options)
set (Boost_USE_STATIC_LIBS ON)
set (Boost_USE_MULTITHREADED OFF)
set (Boost_USE_STATIC_RUNTIME OFF)
我仍然无法理解为什么它一直在运作。如果有人能澄清我会很感激。无论如何它现在也应该在未来工作。