GCC C Compiler

 

GCC C Compiler

GCC is a short of GNU Compiler Collection, a C compiler for Linux.

 

GCC syntax

$ gcc [options] [source files] [object files] [-o output file]

 

GCC options

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

 

GCC examples

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

 

GCC code generator

  Programming language:  
  Compiler:  
  Build type:    
Options
Warning messages level:    
Debug level:    
Optimization level:    
Print compilation info (-v)      
Files / folders
Source files: all
Object files: all
Include directories:    
Library files:      
Library directories:    
Output file:    

Copy code and paste it in terminal.

 

See also

©️ 2024 CalculatorX. All rights reserved.