Skip to content

Instantly share code, notes, and snippets.

@Choumingzhao
Last active August 17, 2021 02:34
Show Gist options
  • Save Choumingzhao/d72867393d1ce5e239728db7109dd739 to your computer and use it in GitHub Desktop.
Save Choumingzhao/d72867393d1ce5e239728db7109dd739 to your computer and use it in GitHub Desktop.
C/C++ newbee pitfalls

The GCC compile command is sensitive to the order of the arguments

$ gcc -o prog prog.c -lncurses and $gcc -lncurses -o prog prog.c behave differently. The latter one will fail according to the comment to his question and this entry in GCC doc.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment