gcc -o hello hello.c
- Create executable with name hello
gcc -c hello.c
- Preprocess and compile only
gcc hello.o -lm
- tells the compiler(ie. gcc) to link the executable file with the given library (math.h here)
gcc -x c hello.txt
- -x
option asks for source language
gcc -std=89 hello.c
- -std
option is for specifying standard
gcc -I ./sources -o hello hello.c
- -I
option is for path to header files
gcc -c greet.c
- Create greet.o
after compiling greet.c
ar cr libgreet.a greet.o
- Create static library (archive) from object file
ar -tvf libgreet.o
- See the contents of an archive file
gcc -L ./ -o hello hello.c -lm -lgreet
- -L
option specifies the directory to search the static library
gcc -c -fPIC greet.c
- Generate object file in fixed position code format
gcc hello.o -shared -o libgreet.so
- Create dynamic library (.so) from object file
gcc -I ./headers -L ./ -o hello hello.c -lgreet
- Link dynamic library during linking stage
-Wall
- enable all the compile time warning messages
-O<level>
- This option is used to specify the code optimisation level. <level>
here is an integer. This way while generating binary code for macros, or loop statements, or pointer/string operations, gcc can produce more efficient/faster code.
-g
- Adds extra information to the executable which can be used for debugging
-S
- Used to produce the compilation output in an assembly language, i.e. a step just before the code generation. It produces a .s
file while contains program in assembly code.