Questions about clang options


I am quite new to LLVM. I just compiled LLVM and clang on Ubuntu11.10 then followed the tutorial

clang -cc1 -O0 -g -emit-llvm showdebug.c

where showdebug.c contains:

int main()
return 0;

But I got
Fatal error: ‘stdio.h’ file not found.


clang showdebug.c

has no problem. I know -g means to generate debug information, -emit-llvm means use the llvm representation for assembler and object files.

Then what do -cc1 and -O0 mean?


-O0 means "turn off optimization". -cc1 means "please screw up my
compilation in mysterious ways".


Dear Zhang,

Compiler ends up invoking cc1 (the backend) anyways. So if you would
like to invoke it by hand, the only thing to know is the right
combination of options. Try to use the compiler verbose option "-v".
It will show you how exactly clang invokes the backend:

clang -v -c showdebug.c

clang version 3.2 (trunk 156703)
Target: x86_64-unknown-linux-gnu
Thread model: posix
"/opt/kernelgen/bin/clang" -cc1 -triple x86_64-unknown-linux-gnu
-emit-obj -mrelax-all -disable-free -main-file-name showdebug.c
-mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose
-mconstructor-aliases -munwind-tables -target-cpu x86-64
-target-linker-version 11 -momit-leaf-frame-pointer -v -coverage-file
showdebug.o -resource-dir /opt/kernelgen/bin/../lib/clang/3.2
-fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem
/usr/local/include -internal-isystem
/opt/kernelgen/bin/../lib/clang/3.2/include -internal-externc-isystem
/include -internal-externc-isystem /usr/include
/RHM/users/work/dmikushin/forge/kernelgen/trunk/src -ferror-limit 19
-fmessage-length 173 -mstackrealign -fgnu-runtime
-fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi
-fdiagnostics-show-option -fcolor-diagnostics -o showdebug.o -x c
clang -cc1 version 3.2 based upon LLVM 3.2svn default target
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
End of search list.

Happy hacking,
- Dima.

Thank you guys for the answer. These definitely help a lot:)