[英]Boost linking using cmake
我正在使用linux,我的CMakeList.txt文件是
cmake_minimum_required(VERSION 2.8)
set(Boost_INCLUDE_DIR /usr/local/include)
set(Boost_LIBRARY_DIR /usr/local/lib)
set(CMAKE_CXX_FLAGS "-lboost_program_options")
find_package(Boost 1.55 COMPONENTS system program_options filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
if(NOT Boost_FOUND)
message(FATAL_ERROR "boost not found")
endif()
add_executable(main main.cpp)
target_link_libraries( main ${Boost_LABRARIES} )
而且我收到以下錯誤。 我從兩天開始研究它,現在我已經厭倦了。 任何人都可以幫我嗎.cmake_
錯誤:
main.cpp:(.text+0x1d): undefined reference to
`boost::program_options::options_description::m_default_line_length'
main.cpp:(.text+0x28): undefined reference to
`boost::program_options::options_description::m_default_line_length'
main.cpp:(.text+0x6a): undefined reference to
`boost::program_options::options_description::options_description(std::string const&, unsigned int, unsigned int)'
collect2: error: ld returned 1 exit status
make[2]: *** [main] Error 1
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2
您有一個錯字: Boost_LABRARIES
應該是Boost_LIBRARIES
。 您還應該刪除SET(CMAKE_CXX_FLAGS ...
行,這在使用CMake時不需要鏈接到庫(並且始終不可移植)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.