-llibrary
-l library
[...]
It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded.
The order in which the link options are placed in relation to the input files matter for certain linkers (gnu ld, for example)
GCC docs: https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html Relevant excerpt:
Interesting stack overflow question on the subject: https://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc