0

我在linux下有一个链接器问题。这是我的cmake文件:

cmake_minimum_required(VERSION 2.6)

# Locate GTest
find_package(GTest REQUIRED Boost)
include_directories(${GTEST_INCLUDE_DIRS})

file(GLOB info_model

"../src/info_model/*.h"
"../src/info_model/*.cpp"
"../src/gcc_xml_parsing/*.h"
"../src/gcc_xml_parsing/*.cpp"
"../src/messages_filed_with_values/*.h"
"../src/messages_filed_with_values/*.cpp"

)

# Link runTests with what we want to test and the GTest and pthread library

add_library(info_model_lib STATIC ${info_model} )

add_executable(runTests_xml unit/gcc_xml_parsing/ut_XMLFile.cpp )
add_executable(runTests_hexDumpUtil unit/info_model/ut_HexDumpUtil.cpp )
add_executable(runTests_cstruct  unit/info_model/ut_CStruct.cpp )
add_executable(runTests_primitive_type_field unit/info_model/ut_PrimitiveTypeField.cpp )
add_executable(runTests_enumField unit/info_model/ut_EnumField.cpp )
add_executable(runTests_ArrayOfFields unit/info_model/ut_ArrayType.cpp )

target_link_libraries(runTests_xml ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread      boost_regex boost_thread info_model_lib)
target_link_libraries(runTests_hexDumpUtil ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread  boost_regex boost_thread info_model_lib)
target_link_libraries(runTests_cstruct ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread  boost_regex boost_thread info_model_lib)
target_link_libraries(runTests_primitive_type_field ${GTEST_LIBRARIES}     ${GTEST_MAIN_LIBRARIES} pthread boost_regex boost_thread info_model_lib)
target_link_libraries(runTests_enumField ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES}     pthread boost_regex boost_thread info_model_lib)
target_link_libraries(runTests_ArrayOfFields ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread boost_regex boost_thread info_model_lib)

然而,链接器抛出一个错误,它开始(我没有提供整个日志,因为它比下面的大 5 倍):

libinfo_model_lib.a(XMLFile.cpp.o): In function `bool    boost::regex_search<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags, __gnu_cxx::__normal_iterator<char const*, std::string>)':

感谢您的帮助

4

1 回答 1

1

你必须在 boost::regex 之前链接你的库

target_link_libraries(runTests_xml ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} info_model_lib  pthread boost_regex boost_thread )
于 2013-08-19T06:45:55.207 回答