У меня возникли проблемы с пониманием следующей ошибки.Неопределенная ошибка ссылки, несмотря на связывание целевых библиотек
У меня есть объявление/определение класса в ball_popping.h/ball_popping.cpp. Класс - шаблонный класс.
Я хочу скомпилировать вышеуказанное как библиотеку и связать их с моим основным файлом game.cpp, который использует функции-члены вышеуказанного класса.
Мой CMakeLists.txt, как показано ниже,
set(EXECUTABLE_NAME ball_popping)
set(LIBRARY_NAME ball_popping_lib)
add_library(${LIBRARY_NAME} STATIC ball_popping.cpp ${INCLUDE_FILES})
add_executable(${EXECUTABLE_NAME} game.cpp)
target_link_libraries(${LIBRARY_NAME} ${Precompiled_LIBRARIES})
target_link_libraries(${EXECUTABLE_NAME} ${LIBRARY_NAME})
Библиотека компилируется и успешно. Исполняемый файл успешно компилируется, но линкер выдает ошибку
CMakeFiles/ball_popping.dir/game.cpp.o: In function `int proficio_main<3ul>(int, char**, barrett::ProductManager&, barrett::systems::Wam<3ul>&, config)':
game.cpp:(.text._Z13proficio_mainILm3EEiiPPcRN7barrett14ProductManagerERNS2_7systems3WamIXT_EEE6config[int proficio_main<3ul>(int, char**, barrett::ProductManager&, barrett::systems::Wam<3ul>&, config)]+0x553): undefined reference to `ballpopping::BallPopping<3ul>::BallPopping(barrett::math::Matrix<3, 1, barrett::units::CartesianPosition> const&, UserGravComp<3ul>&, bool const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
game.cpp:(.text._Z13proficio_mainILm3EEiiPPcRN7barrett14ProductManagerERNS2_7systems3WamIXT_EEE6config[int proficio_main<3ul>(int, char**, barrett::ProductManager&, barrett::systems::Wam<3ul>&, config)]+0x1176): undefined reference to `ballpopping::BallPopping<3ul>::InEllipsoid(barrett::math::Matrix<3, 1, barrett::units::CartesianPosition> const&) const'
game.cpp:(.text._Z13proficio_mainILm3EEiiPPcRN7barrett14ProductManagerERNS2_7systems3WamIXT_EEE6config[int proficio_main<3ul>(int, char**, barrett::ProductManager&, barrett::systems::Wam<3ul>&, config)]+0x119a): undefined reference to `ballpopping::BallPopping<3ul>::IsDistanced(barrett::math::Matrix<3, 1, barrett::units::CartesianPosition> const&)'
CMakeFiles/ball_popping.dir/game.cpp.o:(.rodata._ZTVN11ballpopping11BallPoppingILm3EEE[vtable for ballpopping::BallPopping<3ul>]+0x28): undefined reference to `ballpopping::BallPopping<3ul>::operate()'
collect2: ld returned 1 exit status
конструктор для BallPopping, вКонтакте() и InEllipsoid() определяются в пределах ball_popping.cpp.
Я хотел бы знать, является ли это ошибкой cmake. Я не могу думать, что это ошибка кодирования, так как моя библиотека компилируется и ссылки успешно.
Не может быть уверен без кода, но поскольку вы упоминаете «ball_popping.h/ball_popping.cpp», это звучит так, как будто вы запущены [Почему шаблоны могут быть реализованы только в файле заголовка?] (Http: // stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file) – user4581301
Это было место на. Я изменил код, чтобы включить реализацию как .tpp-файл в конец файла заголовка. Благодарю за ваш ответ. – ZincFur