Вопрос

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top