Reputation: 2181
I'm confusing when creating a static library in C/C++ with same funtion names and param lists but implemented in different source files.
Say, I have play()
funtion declared in test.h
, and play()
implemented in both test.c
and test_old.c
. When creating a library that include both test.c
and test_old.c
in usually manner, there will be no error.
But this will make people confusing when using this library. How to detect this replicated implementation?Thanks.
Upvotes: 2
Views: 200
Reputation: 1177
Duplicating function names in your static library is very bad practice. Don't do this.
That said you can check for duplicate definitions by examining the output of the nm
application.
$ nm libstest.a
test1.c.o:
0000000000000000 T bla
test2.c.o:
0000000000000000 T bla
The following command lists duplicate functions in your library:
$ nm libstest.a | grep -P "^[^\\s]+ T " | cut -d' ' -f3 | sort | uniq -d
Upvotes: 5