找到有问题的宏

时间:2017-08-29 17:21:37

标签: c++ macros clion

自从我加入项目以来,我的编译输出总是如下:

[  0%] Building CXX object lib-tests/gmock/CMakeFiles/gmock_main.dir/gtest/src/gtest-all.cc.o
<command-line>:0:23: warning: ISO C99 requires whitespace after the macro name
<command-line>:0:20: warning: ISO C99 requires whitespace after the macro name
<command-line>:0:23: warning: ISO C99 requires whitespace after the macro name
<command-line>:0:20: warning: ISO C99 requires whitespace after the macro name
[  0%] Building CXX object lib-tests/gmock/CMakeFiles/gmock_main.dir/src/gmock-all.cc.o
<command-line>:0:23: warning: ISO C99 requires whitespace after the macro name
<command-line>:0:20: warning: ISO C99 requires whitespace after the macro name
<command-line>:0:23: warning: ISO C99 requires whitespace after the macro name
<command-line>:0:20: warning: ISO C99 requires whitespace after the macro name
[  0%] Building CXX object lib-tests/gmock/CMakeFiles/gmock_main.dir/src/gmock_main.cc.o
<command-line>:0:23: warning: ISO C99 requires whitespace after the macro name
<command-line>:0:20: warning: ISO C99 requires whitespace after the macro name
<command-line>:0:23: warning: ISO C99 requires whitespace after the macro name
<command-line>:0:20: warning: ISO C99 requires whitespace after the macro name
[  0%] Linking CXX static library libgmock_main.a
[  0%] Built target gmock_main

等等。在编译整个项目的每个文件之间始终存在这种警告,最高可达100%。这只是编译的开始,它从谷歌测试库开始,但我并没有特别怀疑它是坏宏的来源。 (但它可能是)它很奇怪,因为当我谷歌这个警告时,人们得到代码和宏的快照,但我的编译器不这样做,我只是得到警告。

我在Debian上使用CLion和gnu编译器以及cmake。我已经尝试了多个正则表达式来查找没有空格的宏但是没有找到任何成功。如何识别生成此警告的宏?

1 个答案:

答案 0 :(得分:1)

感谢@ stefan对我的问题的评论,从我的CMakeLists.txt文件中删除2个标记解决了这个问题。

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -Wall -O0 -g -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_RULE_MESSAGES:BOOL=ON")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -Wall -O0 -g")

我仔细检查并删除那些标记不会隐藏编译器警告,如未使用的变量等。我不确定删除这些标志可以有什么效果。