问题
I am looking for LLVM (or clang) equivalent of gcc's -D flag which enables macro definition at commandline.
Any pointers would be great.
回答1:
From clang --cc1 --help
:
...
-D <macro> Predefine the specified macro
...
As a rule of thumb, assume that Clang emulates GCC, unless proven otherwise!
回答2:
The default clang
invocation is a gcc-like compiler driver, supporting the same options as gcc, including -D
:
: ~$ cat test/z.c
int foo() {
return FOOBAR;
}
: ~$ clang -DFOOBAR -E -c test/z.c
# 1 "test/z.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 154 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "test/z.c" 2
int foo() {
return 1;
}
So if you want to replace gcc, just invoke clang
. clang -cc1
invokes the front-end component of clang, not the generic compiler driver.
来源:https://stackoverflow.com/questions/15385881/llvm-equivalent-of-gcc-d-macro-definition-on-commandline