当-pedantic开启时,在GCC中抑制“额外';'”错误

时间:2010-04-20 14:01:47

标签: gcc g++ compiler-errors

我正在使用-pedantic标志构建我的程序,这会导致extra ';'错误(因为第三方标头使用了一些不一致的宏; {{1}时错误未显示} 已关闭)。我真的不想关闭-pedantic,也不想编辑标题。有没有办法抑制这个确切的错误?像-pedantic编译器开关一样?

3 个答案:

答案 0 :(得分:3)

在传递包含路径时使用-isystem而不是-I,然后GCC不会警告您有关系统标头的信息。

对于您维护的任何标题,只需编辑它们即可。

答案 1 :(得分:3)

你可以像这样抑制外部标题的迂腐警告:

//save compiler switches
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"

//Bad headers with problem goes here
#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>

//restore compiler switches
#pragma GCC diagnostic pop

答案 2 :(得分:2)

解决方法是删除-pedantic。在这种情况下没有其他任何工作。