“未定义的参考”来自 ld 的错误
这并不像标题让您想象的那么天真。
对于第三方共享库中的几个函数符号,我收到来自链接器/ld 的“未定义引用”错误,我正尝试将其与可执行文件链接。
奇怪的是,该库本身应该包含有问题的符号的定义。
奇怪的是,我的项目中有几个可执行文件,有些面临这个问题,有些则没有。
我是否弄乱了 gcc/ld 标志还是其他原因?
This isn't as naive as the title may lead you to think.
I receive an "Undefined Reference" Error from the linker/ld for a couple of function symbols in third party shared library, that I'm trying to link with my executable.
The strange part is, that library itself is supposed to contain the definition for the offending symbols in question.
The stranger part is that there are several executables in my project, with some facing this problem and some not.
Have I messed up my gcc/ld flags or is it something else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您检查过您的链接顺序吗?这在最新版本的 GCC 中变得更加严格。
例如,一个常见的问题是这样做引起的:
而不是这样:
如果库标志是相互依赖的,那么它们的顺序也很重要。
有一些用于执行库多次传递的标志可能会帮助您解决问题。与上面相同,但使用链接器“分组”库并对它们进行递归链接(以链接器性能成本),您可以执行如下操作:
其中
-Wl,
将选项传递给链接器...在本例中是--start-group
和--end-group
。关于为什么链接顺序很重要的一个很好的类比是这里
我希望有所帮助。
Have you checked your link order? This has gotten stricter in recent versions of GCC.
For example a common problem is caused by doing this:
instead of this:
It also matters which order the library flags are, if they are interdependent.
There are flags for doing a library multi-pass which might help you solve your problem. To to the same as above but with the linker 'grouping' libraries and doing a recursive link on them (at a linker performance cost) you could do something like the following:
Where
-Wl,<option>
passes an option to the linker... in this case--start-group
and--end-group
.A great analogy of why link order is important is here
I hope that helps.
从您的描述中无法判断,其中包含的有用信息大约为零。一种可能是您没有在某些源文件中包含正确的头文件。
Impossible to say from your description, which contains approximately zero useful information. One possibility is that you are not including the correct header file in some source files.