|
|
[webhome] [C++]
GNU C/C++ Compiler (GCC) Cheat sheet
GCC manual can be invoke using info command at the terminal screen.
GCC Options
-S : output only assembly code (file.s extension)
| $ gcc -S demo.c |
for C code, create demo.s assembly code |
| $ g++ -S demo.cpp |
for C++ code, create demo.s assembly code file |
-c : create object file (file.o extension)
| $ g++ -c demo.cpp |
Create demo.o object code file |
-o filename : output specified executable filename
| $ g++ main.cpp runner.cpp -o run |
Compile source code and create run executable code file |
| $ g++ main.o runner.o -o run |
Compile object code and create run executable code file |
-P : output result of preprocessor
| $ g++ -P demo.cpp |
Compile source code and output result of preprocessor a.out |
-g : prepare compiled program for debugging
| $ g++ -g demo.cpp |
Compile source code and prepare executable a.out for gdb (debugger) |
-O : optimize compilation
| $ g++ -O demo.cpp |
Optimize compilation of source code and output a.out |
-lfilename : link system library by name of filename
| $ g++ demo.cc -o demo -lrunner |
Link library librunner.so file to source code demo.cc for compilation
and output demo executable file.
Note:
-lrunner instruct the compiler to first look for file librunner.so file
(shared libraries generally located in /usr/lib and /lib directories).
|
|