LLVM equivalent of gcc -D macro definition on commandline

ぃ、小莉子 提交于 2019-12-08 14:43:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!