[英]C++ runtime symbol lookup error, ubuntu
I have a C++ function doSth that will call a function "checkFrame" from a class "canMsg" as shown below 我有一个C ++函数doSth,它将从类“ canMsg”中调用函数“ checkFrame”,如下所示
#include "canMsg.h"
void doSth(char* canFrame){
map<int, double> returnedData;
CANMsg canMsg;
std::cout<<canFrame <<endl;
canMsg.checkFrame(canFrame);
}
During compilation I receive no error, but when I run it, it executes std::cout<<canFrame <<endl;
在编译期间,我没有收到任何错误,但是在运行它时,它执行了
std::cout<<canFrame <<endl;
statement and crashes by creating an error 语句并通过创建错误而崩溃
undefined symbol: _ZNSaIcEC1Ev, version GLIBCXX_3.4
Any ideas how to fix this? 任何想法如何解决这一问题?
This error can occur when dependent library(where _ZNSaIcEC1Ev
id defined) was compiled for other version of GLIBC (newer version or much older), that you currently have. 当为您当前拥有的其他版本的GLIBC(较新版本或更旧)编译了依赖库(其中定义了
_ZNSaIcEC1Ev
ID)时,会发生此错误。
Try to recompile that library with your current environment. 尝试使用当前环境重新编译该库。
Also you can add nice switch to LDFLAGS
of your app: -Wl,--no-undefined
. 您也可以在应用程序的
LDFLAGS
中添加漂亮的开关: -Wl,--no-undefined
。 Then you can see any undefined symbols at compile time (not sure if it helps in your situation). 然后,您可以在编译时看到任何未定义的符号(不确定是否对您有帮助)。
I think that kind of problem can arise if things are linked in the 'wrong' order. 我认为如果事物以“错误”的顺序链接,就会出现这种问题。 I suggest you try changing the order of whatever libraries you are passing to the linker.
我建议您尝试更改传递给链接器的所有库的顺序。
(I don't actually know why the ordering matters - but it sometimes does.) (我实际上不知道为什么订购很重要-但有时确实如此。)
Thanks for the replies. 感谢您的答复。 The error was due to my attempt to return a locally declared pointer.
该错误是由于我尝试返回本地声明的指针而引起的。 After I changed the local pointer variable to a static, it works perfect.
在将本地指针变量更改为静态变量后,它可以正常工作。 The basic idea is C++ does not advocate to return the address of a local variable to outside of the function.
基本思想是C ++不主张将局部变量的地址返回到函数外部。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.