openwrt GCC 编译错误:error: #pragma GCC diagnostic not allowed inside functions

 

1.  在编译glib2(version 2.50)库的时候,发现本地gcc有些特性不支持,导致编译出错,发现本地gcc版本太低4.4,而下面出现错误的新特性4.6之后才支持,那么有两种解决方法:1.升级gcc 2. 删除源代码这些代码

2. #paragma GCC diagnostic options 

gdate.c:2442: warning: expected [error|warning|ignored] after '#pragma GCC diagnostic'

gdate.c: In function 'g_date_strftime':

gdate.c:2500: error: #pragma GCC diagnostic not allowed inside functions

gdate.c:2501: error: #pragma GCC diagnostic not allowed inside functions

gdate.c:2503: error: #pragma GCC diagnostic not allowed inside functions

gdate.c: At top level:

gdate.c:2559: warning: expected [error|warning|ignored] after '#pragma GCC diagnostic'

3.关于 #paragma GCC diagnostic 相关语法

语法: #pragma GCC diagnostic [error|warning|ignored] "-W<警告选项>"

  • 诊断-忽略:(关闭警告)

  #pragma  GCC diagnostic ignored  "-Wunused"
  #pragma  GCC diagnostic ignored  "-Wunused-parameter"

  • 诊断-警告:(开启警告)

  #pragma GCC diagnostic warning "-Wunused"

  #pragma GCC diagnostic warning "-Wunused-parameter"

  • 诊断-错误:(开启警告-升级为错误)

  #pragma GCC diagnostic error "-Wunused"

  #pragma GCC diagnostic error "-Wunused-parameter"

4.一般代码会用push 和pop操作,用来指定哪一段代码需要忽略或者开启某些编译参数特性,例如:

  #pragma GCC diagnostic push
  #pragma GCC diagnostic ignored "-Wformat-nonliteral"
   代码段.........
 #pragma GCC diagnostic pop

你可能感兴趣的:(OpenWrt,GCC/C/C++,#pragma,GCC,diagnostic,not,all,glib2)