GCC: compilation process..
gcc -Iproj/src myfile.c -o myfile gcc -c myfile.c "compile without linking gcc -D DEBUG myfile.c -o myfile gcc -glevel "level=0,1,3,null "gcc -l links with a library file. "gcc -L looks in directory for library files. "Link -l with library name without the lib prefix and the .a or .so extensions gcc myfile.c -o myfile gcc -Wall "enable all warnings..
gcc
-I -L -l -D -g -O -o -Wall
about the -0 option.. ref to the following table..
Set the compiler's optimization level.
option | optimization level | execution time | code size | memory usage | compile time |
---|---|---|---|---|---|
-O0 | optimization for compilation time (default) | + | + | - | - |
-O1 or -O | optimization for code size and execution time | - | - | + | + |
-O2 | optimization more for code size and execution time | -- | + | ++ | |
-O3 | optimization more for code size and execution time | --- | + | +++ | |
-Os | optimization for code size | -- | ++ | ||
-Ofast | O3 with fast none accurate math calculations | --- | + | +++ |
+increase ++increase more +++increase even more -reduce --reduce more ---reduce even more
some environmental variables used in gcc: for more, see here
LANG 1
LC_CTYPE 1
LC_MESSAGES 1
LC_ALL 1
TMPDIR 1
GCC_COMPARE_DEBUG 1
GCC_EXEC_PREFIX 1
COMPILER_PATH 1
LIBRARY_PATH 1
CPATH 1
C_INCLUDE_PATH 1
CPLUS_INCLUDE_PATH 1
OBJC_INCLUDE_PATH 1
DEPENDENCIES_OUTPUT 1
SUNPRO_DEPENDENCIES 1
SOURCE_DATE_EPOCH 1
-----to ensure how a lib is generated, by:
objdump --debugging *.a/*.so
part 2:------original file ends, adding more gcc options-----
from here:
-v, -save-temps, -S, -c, -E, -Werror, -fPIC, -ansi, -funsigned-char, -pg. -Wextra, -Wfloat-equal, -pipe, -funroll-loops (code size up), -flto (e.g. inline opt)
@filename to specify options in file.
Note, from here and here, -march/-mtune is very powerful, specify different arch/tune mighe influence final code. And march is stronger than mtune, it enables generating code that may not be run other than the specified cpu.
gprof usage: -pg option used while compile & linking, then ./a.out then a file named gmon.out is generated. Then use gprof a.out gmon.out > gprof.txt generate a profile for human readable format of gprof.
valgrind tutorial is here.