I have two libraries, named a.lib and b.lib. Both libraries have a function char test(void), but return different characters.
a.c (a.lib)
char test(void);char test(void) { return 'a';}
b.c (b.lib)
char test(void);char test(void) { return 'b';}
I create a project link these two libraries and call test() in main() function.
main.c
char test(void);int main(){ char c = test(); return 0; }
I expected it should be "Error: L6200E: Symbol multiply defined" error, but " 0 errors".
Why is there no link error?
Thanks for the reply.
Because it is a library not an object?
The linker pulls from the first library it can achieve closure with, that's why the ordering of libraries is important.
The library can contain multiple objects, if pulling in your symbol draws in a larger object with other symbols, these may conflict in your namespace resulting in a multiply defined error.
This is also why the compiler has option to create a new object for each function.
A book on linker design may explain this better.
Thanks for your reply.
Do I have any chance to find out the same function name in two or more libraries?
View all questions in Keil forum