g++链接器顺序问题
我试图找出在 Qt Creator 中编译代码时导致错误的原因,即链接到我的外部构建的库中。
它抱怨“对 myclass::myclass(args) 的未定义引用”构造函数。
但是,此类已构建,并且目标文件包含在名为 common.a 的存档中。
引用 myclass 的代码实际上位于另一个库中,名为 CSV.a
所以,我知道我的 Qt 项目可以看到 CSV.a,并且我知道还有其他对 common.a 内容的引用,它并没有抱怨,但是显然,在这种安排中,CSV.a 中的内容看不到 common.a 中的内容。
我需要做哪些不同的事情?
I am trying to figure out something that is causing an error when trying to compile code in Qt Creator, that is linking in my externally built libraries.
It is complaining about an "undefined reference to myclass::myclass(args)" constructor.
However, this class has been built, and the object file was included in an archive called common.a .
The code that references myclass is actually in another library, called CSV.a
So, I know my Qt project can see CSV.a, and I know that there are other references to stuff in common.a that it is not complaining about, but apparently the stuff in CSV.a can't see the stuff in common.a in this arrangement.
What do I need to do differently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
链接器使用命令行上列出库的顺序来确定实际需要哪些符号。您需要按照从最依赖到最不依赖的顺序对它们进行排序,以便它可以做出决定。例如,首先列出 CSV.a,以便编译器知道它需要在某处找到 myclass::myclass(args) 。然后列出common.a,然后编译器将找到并链接该构造函数。
The linker uses the order that libraries are listed on the command line to determine which symbols are actually needed. You need to order them from most-dependent to least-dependent so it can make that determination. For example, list
CSV.a
first so the compiler knows that it needs to findmyclass::myclass(args)
somewhere. Then listcommon.a
second and the compiler will then find and link that constructor.您可能需要确保在链接器命令行上
CSV.a
后跟common.a
,而不是相反。You may need to make sure that on the linker command line
CSV.a
is followed bycommon.a
, not the other way around.