我正在使用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
答案 0 :(得分:1)
您有一个拼写错误:Boost_LABRARIES
应为Boost_LIBRARIES
。您还应该删除SET(CMAKE_CXX_FLAGS ...
行,这在使用CMake时从不需要链接到库(无论如何它都是非便携式的。)