我正在使用CMAKE构建我的项目:
cmake_minimum_required(VERSION 3.14)
set (CMAKE_CXX_STANDARD 11)
project(saryxo_checker)
find_package( OpenCV REQUIRED )
find_package( Boost 1.71 REQUIRED COMPONENTS program_options filesystem system )
set(SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/src/main.cpp
${CMAKE_CURRENT_LIST_DIR}/src/FeatureEvaluator.cpp
${CMAKE_CURRENT_LIST_DIR}/src/Converter.cpp
${CMAKE_CURRENT_LIST_DIR}/core/util.cpp)
include_directories(
${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_CURRENT_LIST_DIR}/core
${OpenCV_INCLUDE_DIR}
${Boost_INCLUDE_DIR})
add_executable(saryxo_checker ${SOURCE_FILES})
target_link_libraries(saryxo_checker ${OpenCV_LIBS} ${Boost_LIBRARIES})
但是,在链接过程中会引发错误。错误会在Boost内部抛出。
[ 20%] Linking CXX executable saryxo_checker
CMakeFiles/saryxo_checker.dir/src/main.cpp.o: In Function »__static_initialization_and_destruction_0(int, int)«:
/usr/local/include/boost/system/error_code.hpp:221: Warning: undefined reference to »boost::system::generic_category()«
/usr/local/include/boost/system/error_code.hpp:222: Warning: undefined reference to »boost::system::generic_category()«
/usr/local/include/boost/system/error_code.hpp:223: Warning: undefined reference to »boost::system::system_category()«
CMakeFiles/saryxo_checker.dir/src/main.cpp.o: In function »boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char const* const*)«:
/usr/local/include/boost/program_options/detail/parsers.hpp:44: Warning: undefined reference to »boost::program_options::detail::cmdline::cmdline(std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)«
CMakeFiles/saryxo_checker.dir/src/main.cpp.o:(.data.rel.ro._ZTVN5boost15program_options11typed_valueIicEE[_ZTVN5boost15pro ram_options11typed_valueIicEE]+0x40): Warning: undefined reference to »boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool) const«
CMakeFiles/keypoint_tracker_evaluator_saryxoS_Trian.dir/src/main.cpp.o:(.data.rel.ro._ZTVN5boost15program_options11typed_valueIjcEE[_ZTVN5boost15program_options11typed_valueIjcEE]+0x40): Warning: undefined reference to »boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool) const«
CMakeFiles/saryxo_checker.dir/src/main.cpp.o:(.data.rel.ro._ZTVN5boost15program_options11typed_valueINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEE[_ZTVN5boost15program_options11typed_valueINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEE]+0x40): Warning: undefined reference to »boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool) const«
CMakeFiles/saryxo_checker.dir/src/main.cpp.o: In function »boost::program_options::typed_value<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char>::xparse(boost::any&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) const«:
/usr/local/include/boost/program_options/detail/value_semantic.hpp:167: Warning: undefined reference to »boost::program_options::validate(boost::any&, std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, int)«
CMakeFiles/saryxo_checker.dir/src/FeatureEvaluator.cpp.o: In function »__static_initialization_and_destruction_0(int, int)«:
/usr/local/include/boost/system/error_code.hpp:221: Warning: undefined reference to »boost::system::generic_category()«
/usr/local/include/boost/system/error_code.hpp:222: Warning: undefined reference to »boost::system::generic_category()«
/usr/local/include/boost/system/error_code.hpp:223: Warning: undefined reference to »boost::system::system_category()«
CMakeFiles/saryxo_checker.dir/src/Converter.cpp.o: In function »__static_initialization_and_destruction_0(int, int)«:
/usr/local/include/boost/system/error_code.hpp:221: Warning: undefined reference to »boost::system::generic_category()«
/usr/local/include/boost/system/error_code.hpp:222: Warning: undefined reference to »boost::system::generic_category()«
/usr/local/include/boost/system/error_code.hpp:223: Warning: undefined reference to »boost::system::system_category()«
CMakeFiles/saryxo_checker.dir/src/Converter.cpp.o: In function »boost::system::error_code::error_code()«:
/usr/local/include/boost/system/error_code.hpp:322: Warning: undefined reference to »boost::system::system_category()«
CMakeFiles/saryxo_checker.dir/src/Converter.cpp.o: In function »boost::system::error_code::clear()«:
/usr/local/include/boost/system/error_code.hpp:350: Warning: undefined reference to »boost::system::system_category()«
CMakeFiles/saryxo_checker.dir/core/util.cpp.o: In in function »__static_initialization_and_destruction_0(int, int)«:
/usr/local/include/boost/system/error_code.hpp:221: Warning: undefined reference to »boost::system::generic_category()«
/usr/local/include/boost/system/error_code.hpp:222: Warning: undefined reference to »boost::system::generic_category()«
/usr/local/include/boost/system/error_code.hpp:223: Warning: undefined reference to »boost::system::system_category()«
collect2: error: ld returned 1 exit status
CMakeFiles/saryxo_checker.dir/build.make:179: recipe for target 'saryxo_checker' failed
make[3]: *** [saryxo_checker] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/saryxo_checker.dir/all' failed
make[2]: *** [CMakeFiles/saryxo_checker.dir/all] Error 2
CMakeFiles/Makefile2:84: recipe for target 'CMakeFiles/saryxo_checker.dir/rule' failed
make[1]: *** [CMakeFiles/saryxo_checker.dir/rule] Error 2
Makefile:118: recipe for target 'saryxo_checker' failed
make: *** [saryxo_checker] Error 2
我也尝试在调试模式下构建Boost,因为我也在调试模式下构建程序,但是错误保持不变。会是什么?