如何绕过“多个定义的符号”与 gcc 链接
我使用的是具有 gcc 2.95.3 的旧系统,我必须链接两个对象,尽管它们彼此无关,但它们每个都有相似的命名方法。我无法重命名它们中的任何一个,但我希望有一种方法来构建它们,以免链接器抱怨。它所抱怨的方法都是由对象内的类在内部调用的。我能做些什么?
I am using an older system that has gcc 2.95.3, I have to link in two objects that although they have nothing to do with each other, they each have similarly named methods. I can't rename either of them, but I would hope there is a way to build them as to not have the linker complain. The methods it is complaining about are each internally called by classes within the object. What can I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有完整的 GNU 工具链,您应该能够使用 objcopy 解决您的问题,如下所示(如果我正确理解了您的问题):
这里有两个非常相似的对象,“foo”和“bar”,两者都导出一个名为
clash
的符号 - 该符号在内部使用,但实际上根本不需要导出:and
这是主要代码,它想要同时使用两者:
将它们链接在一起不起作用:
因此,使用 objcopy 来更改一个(或两个,如果您愿意的话!)对象中
clash
的可见性:现在您可以成功地与修改后的对象链接 - 并且程序的行为应如此:
If you have a complete GNU toolchain, you should be able to work around your problem using
objcopy
, like this (if I've understood your problem correctly):Here are two very similar objects, "foo" and "bar", both of which export a symbol called
clash
- which is used internally, but doesn't really need to be exported at all:and
And here's the main code, which wants to use both:
Linking them together doesn't work:
So, use
objcopy
to change the visibility ofclash
in one (or both, if you like!) of the objects:Now you can link successfully with the modified object - and the program behaves as it should: