diff --git a/clang.md b/clang.md index 92d5dd3b9cfbbf3dfafac7ea4dd9f8758d3f03f2..212081a1af51ffdd45b0fedfb422f54753e19a9e 100644 --- a/clang.md +++ b/clang.md @@ -635,3 +635,19 @@ int main() { return 0; } ``` + +## Compiler Options + +Here are some recommended compiler and linker flags for GCC and Clang: + +- `-O2`: optimize your code for speed/space efficiency +- `-Wall`: turn on recommended compiler warnings (_Always use this option, some of the +warnings can save you hours of debugging!_) +- `-Werror`: turn warnings into errors +- `-g`: enable debugging. Need this option if you want to use a debugger such as GDB. +- `-o <output filename>`: Name the output executable file with a given filename. +- `-I <dir>`: add the directory `dir` to the list of directories to be searched for header files. +- `-std=<standard>`: specify the language standard, e.g. `-std=c11` +- `-pedantic`: issue warnings demanded by strict conformance to the stardard +- `-D_FORTIFY_SOURCE=2`: detect runtime buffer overflow +- `-fpie -Wl,-pie`: enable full ASLR(address space layout randomization) for better security