GCC和ld找不到导出的符号...但他们在那里! [英] GCC and ld can't find exported symbols...but they're there!

查看:291
本文介绍了GCC和ld找不到导出的符号...但他们在那里!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++库和一个C ++应用程序,试图使用从库中导出的函数和类。该库建立良好,应用程序编译但无法链接。我得到的错误信息如下:


app-source-file.cpp :( .text + 0x2fdb):未定义的引用-namespace :: GetStatusStr(int)'


库中的类似乎被链接器解析得很好,但是自由函数和导出的数据(如余弦查找表)总是会导致上述错误。

我使用的是Ubuntu 8.04(Hardy),它与最新的Unbuntu



链接库的命令是(除去其他库):

  g ++ -fPIC -Wall -O3 -shared -Wl,-soname,lib-in-question.so -o〜/ project / lib / release / lib-in-question.so 
code>

链接应用程序的命令是(除去其他库):

  g ++ -fPIC -Wall -O3 -L〜/ project / lib / release -llib-in-question -o〜/ project / release / app-in-question 

最后,它显示(最好像I ca n告诉)有问题的符号正在被正确导出:

  nm -D〜/ project / lib / release / lib- |问题grep GetStatusStr  - > U _ZN3lib-namespace12GetStatusStrEi 


解决方案

_ZN3lib-namespace12GetStatusStrEi nm输出显示库中的符号未定义



也许它是在错误的名称空间中定义的:它看起来像是在调用它在lib-namepace中,但你可能会在另一个中定义它。


I have a C++ library and a C++ application trying to use functions and classes exported from the library. The library builds fine and the application compiles but fails to link. The errors I get follow this form:

app-source-file.cpp:(.text+0x2fdb): undefined reference to `lib-namespace::GetStatusStr(int)'

Classes in the library seem to be resolved just fine by the linker, but free functions and exported data (like a cosine lookup table) invariably result in the above error.

I am using Ubuntu 8.04 (Hardy), and it is up to date with the latest Unbuntu packages.

The command to link the library is (with other libraries removed):

g++ -fPIC -Wall -O3 -shared -Wl,-soname,lib-in-question.so -o ~/project/lib/release/lib-in-question.so

The command to link the application is (with other libraries removed):

g++ -fPIC -Wall -O3  -L~/project/lib/release -llib-in-question -o ~/project/release/app-in-question

Finally, it appears (as best as I can tell) that the symbols in question are being exported properly:

nm -D ~/project/lib/release/lib-in-question.so | grep GetStatusStr --> U _ZN3lib-namespace12GetStatusStrEi

解决方案

the U before _ZN3lib-namespace12GetStatusStrEi in the nm output shows that the symbol is undefined in the library.

Maybe it's defined in the wrong namespace: it looks like you're calling it in lib-namepace but you might be defining it in another.

这篇关于GCC和ld找不到导出的符号...但他们在那里!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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