GCC is a short of GNU Compiler Collection, a C compiler for Linux.
$ gcc [options] [source files] [object files] [-o output file]
GCC main options:
option | description |
---|---|
gcc -c | compile source files to object files without linking |
gcc -Dname[=value] | define a preprocessor macro |
gcc -fPIC | generate position independent code for shared libraries |
gcc -glevel | generate debug information to be used by GDB |
gcc -Idir | add include directory of header files |
gcc -llib | link with library file |
gcc -Ldir | look in directory for library files |
gcc -o output file | write build output to output file |
gcc -Olevel | optimize for code size and execution time |
gcc -shared | generate shared object file for shared library |
gcc -Uname | undefine a preprocessor macro |
gcc -w | disable all warning messages |
gcc -Wall | enable all warning messages |
gcc -Wextra | enable extra warning messages |
Compile file1.c and file2.c and link to output file execfile:
$ gcc file1.c file2.c -o execfile
Run output file execfile:
$ ./execfile
Compile file1.c and file2.c without linking:
$ gcc -c file1.c file2.c
Compile myfile.c with debug information and link to output file execfile:
$ gcc -g myfile.c -o execfile
Compile myfile.c with warning messages enabled and link to output file execfile:
$ gcc -Wall myfile.c -o execfile
Compile myfile.c with and link with static library libmath.a located in /user/local/math to output file execfile:
$ gcc -static myfile.c -L/user/local/math -lmath -o execfile
Compile myfile.c with optimization and link to output file execfile:
$ gcc -O myfile.c -o execfile