Gcc detects duplicate characters / functions in static libraries

Is there a way to get gcc to detect duplicate characters in static libraries compared to the main code (or another static library?)

Here's the situation:

main.c mistakenly contains a function definition, for example. with signatureuint foohash(const char*)

foo.c also contains a function definition with a signature uint foohash(const char*)

foo.c and other source files are compiled into a static utility library with which the main program is associated, for example:

 gcc -o main main.o util.o -L ./libs -lfooutils

So now main.o and libs / libfooutils.a contain the foohash function. Presumably, the linker found this symbol in main.o and did not look for it elsewhere.

Is there a way to get gcc to detect such a situation?

+5
source share
3 answers

, , --whole-archive . :

 gcc -o main main.o util.o -L ./libs -Wl,--whole-archive -lfooutils -Wl,--no-whole-archive

.

+3

: .

GCC . ld, ( GCC) , .

joggery pokery , , , , , , - undefined .

, (pass -t to gcc), , . nm script .

+2

gcc ld . ld:

--no-define-common
--traditional-format
--warn-common

. ld. , , .

+2

All Articles