Strange error: undefined reference to `class::class()'

痴心易碎 提交于 2019-12-14 04:26:23

问题


I have a library irWGN dependent of another library irRNG.

My CMakeFiles.txt's are as follows. The one is src/signals is

add_library(irRNG irRNG.cpp)
add_library(irWGN irWGN.cpp)

and the main CMakeFile

include_directories(${SRC}/signals)
SET(MY_LIB
  ${MY_LIB}
  irRNG
  irWGN
  )
....

foreach(file2link ${FILES_to_RUN})

  target_link_libraries(${file2link}
    ${catkin_LIBRARIES}
    ${Boost_LIBRARIES}
    ${gsl_LIBRARIES}
    ${OpenCV_LIBRARIES}
    ${MY_LIB}
    )
   add_dependencies(${file2link} project_generate_messages_cpp)
endforeach(file2link)

Am getting this error

./devel/lib/libirWGN.so: undefined reference to `irRNG::irRNG()'
../devel/lib/libirWGN.so: undefined reference to `irRNG::~irRNG()'

The strange thing is that I was using this on ubuntu 12.04 without any issue. Only now that this problem appears.


回答1:


Since the problem is that your irWGN depends on your irRNG, the most elegant way to fix your issue would be to add:

target_link_libraries(irWGN irRNG)

Creating an interdependency among your libraries. It works also for static libraries! So, if you try to link an executable to irWGN, cmake will automatically also link to irRNG, and in the correct order.



来源:https://stackoverflow.com/questions/37538967/strange-error-undefined-reference-to-classclass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!