如何从VC8中的2个静态库中获取所有符号冲突

发布于 2024-11-14 08:47:29 字数 315 浏览 8 评论 0原文

假设我有 2 个静态库

ex1.a ex2.a

在两个库中我将定义 10 个相同的函数

当编译示例测试代码时说“test.c”时,我链接到静态库 ex1.a 和 ex2.a

在“test.c”中我将仅调用 3 个函数,那么我会得到 链接器错误“ex1.a 和 ex2.a 库中定义的符号相同”这是好的。

我的问题是: 1.为什么这个错误只显示3个函数作为多重定义..为什么不列出VC8中的所有10个函数

  1. 我如何列出所有多个定义的符号而不在测试代码中实际调用该函数...

谢谢,

Say I have 2 static libs

ex1.a
ex2.a

In both libs I will define 10 same functions

When Compiling a sample test code say "test.c" , I link with both static libs ex1.a and ex2.a

In "test.c" I will call only 3 functions, then I will get the
linker error "same symbols deifned in both ex1.a and ex2.a libraries" This is Ok.

My Question here is :
1. Why this error only display 3 functions as multiple defined.. Why not it list all 10 functions

  1. In VC8 How can I list all multiple defined symbols without actualy calling that function in test code ...

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾听心声的旋律 2024-11-21 08:47:29

那是因为,链接器在编译和链接具有函数调用的代码时尝试解析符号名称。仅当代码有一些函数调用时,链接器才会尝试在测试代码或链接的库中解析它,此时它会找到多个定义。如果没有调用任何函数,那么我想没问题。

Thats because, linker tries to resovle a symbol name, when it compiles and links a code which has the function call. Only when the code has some function calls, linker would try to resolve it in either the test code or the libraries linked along and thats when it would find multiple definitions. If no function called, then I guess no problem.

凉城凉梦凉人心 2024-11-21 08:47:29

您体验到的是链接器的优化部分:默认情况下,它不会包含未引用的代码。编译器将创建多个对象文件,这些文件很可能具有未解决的依赖关系(所包含的代码无法满足的调用)。因此,链接器获取传递的所有目标文件,并尝试为未解决的依赖关系找到解决方案。如果失败,它将检查可用的库文件。如果有多个具有相同名称/签名的选项,它将开始抱怨,因为它将无法决定选择哪一个(对于相同的代码,这并不重要,但想象一下使用不同的“幕后”工作的不同实现在内存上,例如调试和释放内容)。

我能想到的检测所有这些多个定义的唯一(可能也是最简单的方法)是创建另一个静态库项目,包括两个静态库中使用的所有源文件。创建库时,链接器将包含调用或导出的所有内容 - 只要导出了所有内容,您就不需要调用链接器的特定代码来查看/包含所有内容。

但是我仍然不明白你实际上想要完成什么整体目标。试图找到两个库之间共享的代码?

What you experience is the optimizing part of the linker: By default it won't include code that isn't referenced. The compiler will create multiple object files with most likely unresolved dependencies (calls that couldn't be satisfied by the code included). So the linker takes all object files passed and tries to find solutions for the unresolved dependencies. If it fails, it will check the available library files. If there are multiple options with the same exact name/signature it will start complaining cause it won't be able to decide which one to pick (for identical code this won't matter but imagine different implementations using different "behind the scenes" work on memory, such as debug and release stuff).

The only (and possibly easiest way) I could think of to detect all these multiple definitions would be creating another static library project including all source files used in both static libs. When creating a library the linker will include everything called or exported - you won't need specific code calling the stuff for the linker to see/include everything as long as it's exported.

However I still don't understand what you're actually trying to accomplish as a whole. Trying to find code shared between two libraries?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文