开发者

How to get all symbol conflict from 2 static libs in VC8

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 bo开发者_JAVA百科th 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,


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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜