我在cmake-baed boost鏈接問題上掙扎,我在stackoverflow上搜索,但在其他論壇上卻無濟於事。使用cmake連接boost庫lib.8.0
我正在編譯一個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,我得到下面的輸出
[email protected] build]$ emacs ../CMakeLists.txt
Display localhost:39.0 unavailable, simulating -nw
[[email protected] build]$ rm -rf *
[[email protected] 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
問題是當我「作」的代碼如下。
[email protected] 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的顯示提升的lib目錄中/software/apps/boost/1.55.0/build06/lib,奇怪的是在鏈接時,它指的是一個不同的非正在出現目錄。
有人遇到這樣的錯誤嗎?該集羣正在運行CentOS版本6.5,boost(我指向的地方)是1.55.0,我使用的cmake是2.8.8。
您的提升包括目錄也沒有找到正確的? '提升包括目錄是/ usr/include' – fileoffset
你是對的。事實上,當我在與cmake/boost版本相同的不同集羣上嘗試這個例子時,一切都很順利,但是對於當前的機器,它會給出這些奇怪的錯誤。 – Ikram