【发布时间】:2014-06-18 01:40:37
【问题描述】:
我正在努力解决我在 stackoverflow 和其他论坛上搜索的 cmake-baed boost 链接问题,但无济于事。
我正在一个已经安装了 Boost 的集群上编译一个 C++ 程序套件(取决于不同的库,除了 Boost)(我知道完整路径)。在编译时遇到奇怪的 boost 与 cmake 的链接错误后,我想到了首先编译一个非常简单的 boost-cmake 示例来解决问题。
代码如下。
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/option.hpp>
using namespace std;
#include <iostream>
namespace po = boost::program_options;
int main(int argc, char** argv) {
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
;
return 0;
}
我正在使用以下 CMakeLists.txt 文件进行构建。
cmake_minimum_required(VERSION 2.8)
set(Boost_INCLUDE_DIR /software/apps/boost/1.55.0/build06/include)
set(Boost_LIBRARY_DIR /software/apps/boost/1.55.0/build06/lib)
find_package(Boost COMPONENTS program_options REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
message("Boost include dir is ${Boost_INCLUDE_DIR}")
message("Boost library dir is ${Boost_LIBRARY_DIR}")
message("Boost libraries are at ${Boost_LIBRARIES}")
add_executable(main main.cpp)
target_link_libraries( main ${Boost_LIBRARIES} )
当我使用 cmake 编译时,我得到以下输出
x_ikrul@ikramu build]$ emacs ../CMakeLists.txt
Display localhost:39.0 unavailable, simulating -nw
[x_ikrul@triolith1 build]$ rm -rf *
[x_ikrul@triolith1 build]$ cmake ..
-- The C compiler identification is GNU 4.7.2
-- The CXX compiler identification is GNU 4.7.2
-- Check for working C compiler: /software/apps/comp_wrapper/gnu/gcc
-- Check for working C compiler: /software/apps/comp_wrapper/gnu/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /software/apps/comp_wrapper/gnu/c++
-- Check for working CXX compiler: /software/apps/comp_wrapper/gnu/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
Boost found.
Found Boost components:
program_options
Boost include dir is /usr/include
Boost library dir is /software/apps/boost/1.55.0/build06/lib
Boost libraries are at optimized;boost_program_options-mt-shared;debug;boost_program_options-mt-shared-debug
-- Configuring done
-- Generating done
-- Build files have been written to: /home/x_ikrul/Downloads/boost_example/build
当我“制作”下面给出的代码时,问题就来了。
x_ikrul@ikramu build]$make
Scanning dependencies of target main
[100%] Building CXX object CMakeFiles/main.dir/main.cpp.o
make[2]: *** No rule to make target `/usr/lib64/lib64/libboost_program_options-mt.so.5', needed by `main'. Stop.
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2
如您所见,尽管 CMake 显示 boost 的 lib 目录为 /software/apps/boost/1.55.0/build06/lib,但奇怪的是,在链接时,它指的是另一个不存在的目录。
有人遇到过这样的错误吗?集群运行 CentOS 6.5 版,boost(我指的地方)是 1.55.0,我使用的 cmake 是 2.8.8。
【问题讨论】:
-
您的 boost 包含目录也未正确找到?
Boost include dir is /usr/include -
你是对的。事实上,当我在具有相同版本的 cmake/boost 的不同集群上尝试此示例时,一切都很顺利,但在当前机器上,它给出了这些奇怪的错误。