https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99896
Michael Matz <matz at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |matz at gcc dot gnu.org --- Comment #7 from Michael Matz <matz at gcc dot gnu.org> --- (In reply to Jonathan Wakely from comment #1) > (In reply to Tom de Vries from comment #0) > > With g++, we have instead: > > ... > > collect2 ... main.o foo.o -lpcre2-posix ... > > ... > > It isn't dropped, it's moved to the end: > > main.o foo.o -lpcre2-posix -lstdc++ -lm -lc -lgcc_s -lgcc -lc -lgcc_s -lgcc > > If you need it before foo.o then -Wl,-lc seems like the right workaround for > me. Workaround is the correct term here. The correct thing would be for g++ to not reorder -l arguments. The similarity to -I is superficial: duplicated -l arguments have meaning (with static archives for instance) and their position in relation to object and source files matters. g++ can validly tack on additional -l arguments to the end, and arguably also replace a lone -lc argument that was originally at the end of the command line or implicit (e.g. to inject its unwinder), but it shouldn't otherwise reorder such arguments. I will of course agree that the issue that the added -lc "solves" is actually a bug in the testcase (and gdb). But that should be immaterial here. At the very least gcc and g++ should behave the same in this respect.