I am looking for LLVM (or clang) equivalent of gcc's -D flag which enables macro definition at commandline.
Any pointers would be great.
I am looking for LLVM (or clang) equivalent of gcc's -D flag which enables macro definition at commandline.
Any pointers would be great.
From clang --cc1 --help
:
...
-D <macro>=<value> Define <macro> to <value> (or 1 if <value> omitted)
...
As a rule of thumb, assume that Clang emulates GCC, unless proven otherwise!
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.
make cc=/path/to/clang
. I hope that is correct. –
Mera © 2022 - 2024 — McMap. All rights reserved.
clang -cc1 --help
. – Mera