Question

I am looking for LLVM (or clang) equivalent of gcc's -D flag which enables macro definition at commandline.

Any pointers would be great.

Was it helpful?

Solution

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!

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top