https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99896
--- Comment #2 from Tom de Vries <vries 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 > I don't understand. AFAICT, it's dropped. It's not moved to the end, because -lc is already at the end without specifying -lc. > If you need it before foo.o then -Wl,-lc seems like the right workaround for > me. > Um, for my understanding, does that mean you agree this is a bug in g++? > Why is it needed there anyway though? main.o is intended to use regcomp from glibc. Foo.o is intended to use pcre2_regcomp from pcre2-posix (which is also accessible using plain regcomp). When -lc is droppend, regcomp from pcre2-posix is used by main instead, which is incompatible with using re_search from glibc.