GCC和ld找不到导出的符号

GCC和ld找不到导出的符号

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

问题描述

我有一个C ++库和一个C ++应用程序,试图使用从库中导出的函数和类.该库可以正常运行,并且可以编译应用程序,但无法链接.我收到的错误遵循以下格式:

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:

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

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.

我正在使用Ubuntu 8.04(Hardy),并且它是最新的Ubuntu软件包的最新版本.

I am using Ubuntu 8.04 (Hardy), and it is up to date with the latest Ubuntu 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

推荐答案

nm输出中_ZN3lib-namespace12GetStatusStrEi之前的U表明该符号在库中为 undefined .

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

也许它是在错误的命名空间中定义的:似乎您在lib-namepace中调用它,但是您可能在另一个名称中对其进行了定义.

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找不到导出的符号...但是它们在那里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 19:38