friko
friko

Reputation: 607

Linking error after making cmake

I have a linker problem under linux. This is my cmake file:

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)

However, the linker throwns an error, which start (I didn't provide the whole log, because it is 5 times larger than the below):

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>)':

Thank you for helping

Upvotes: 0

Views: 119

Answers (1)

user2597359
user2597359

Reputation: 51

You have to link yours library before boost::regex

target_link_libraries(runTests_xml ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} info_model_lib  pthread boost_regex boost_thread )

Upvotes: 1

Related Questions