https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106483
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> --- Firstly, this is the linker doing this, not GCC. GCC just passes the arguments to the linker in the order you specify them. Secondly, this is the correct behaviour. Your linker is set up to default to --as-needed which means that shared libraries on the command line will only get used if they satisfy a non-weak undefined reference from a regular object file that has already been processed by the linker. If you put -ladd before main.cpp then there are no undefined symbols yet, so the library is just ignored. https://web.archive.org/web/20210609020437/c-faq.com/lib/libsearch.html Either link with -Wl,--no-as-needed to change the linker's behaviour so that shared libraries are always used, or put the libraries in the right order.