奇怪的错误:未定义的引用`class :: class()' [英] Strange error: undefined reference to `class::class()'

查看:501
本文介绍了奇怪的错误:未定义的引用`class :: class()'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个库irWGN依赖于另一个库irRNG。

I have a library irWGN dependent of another library irRNG.

我的CMakeFiles.txt如下。一个是src / signals是

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

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

和主CMakeFile

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)

得到此错误

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

奇怪的是,我在ubuntu 12.04上使用这个没有任何问题。只有现在,这个问题出现。

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

推荐答案

由于问题是您的irWGN取决于您的irRNG,解决您的问题最简单的方法是添加:

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)

创建库之间的相互依赖关系。它也适用于静态库!因此,如果您尝试将可执行文件链接到irWGN,cmake将自动也以正确的顺序链接到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.

这篇关于奇怪的错误:未定义的引用`class :: class()'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆