Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. `gcc -o hello hello.c` - Create executable with name hello
  2.  
  3. `gcc -c hello.c` - Preprocess and compile only
  4.  
  5. `gcc hello.o -lm` - tells the compiler(ie. gcc) to link the executable file with the given library (math.h here)
  6.  
  7. `gcc -x c hello.txt` - `-x` option asks for source language
  8.  
  9. `gcc -std=89 hello.c` - `-std` option is for specifying standard
  10.  
  11. `gcc -I ./sources -o hello hello.c` - `-I` option is for path to header files
  12.  
  13. ## Creating and using Static libraries
  14.  
  15. `gcc -c greet.c` - Create `greet.o` after compiling greet.c
  16.  
  17. `ar cr libgreet.a greet.o` - Create static library (archive) from object file
  18.  
  19. `ar -tvf libgreet.o` - See the contents of an archive file
  20.  
  21. `gcc -L ./ -o hello hello.c -lm -lgreet` - `-L` option specifies the directory to search the static library
  22.  
  23. ### Creating and using Dynamic libraries
  24.  
  25. `gcc -c -fPIC greet.c` - Generate object file in fixed position code format
  26.  
  27. `gcc hello.o -shared -o libgreet.so` - Create dynamic library (.so) from object file
  28.  
  29. `gcc -I ./headers -L ./ -o hello hello.c -lgreet` - Link dynamic library during linking stage
  30.  
  31. ## Other useful flags
  32.  
  33. `-Wall` - enable *all* the compile time warning messages
  34.  
  35. `-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.
  36.  
  37. `-g` - Adds extra information to the executable which can be used for debugging
  38.  
  39. `-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.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement