【问题标题】:Fix this Compile Error: identifier "and" is a special operator name in C++ [-Werror=c++-compat]?修复此编译错误:标识符“and”是 C++ 中的特殊运算符名称 [-Werror=c++-compat]?
【发布时间】:2019-04-09 09:39:54
【问题描述】:

我将 GTK 库添加到我的 C++ 项目中,但出现此错误。 我该如何解决?

此行发生错误:

line 84: GLIB_DEPRECATED_IN_2_54_FOR(g_object_new_with_properties and g_initable_init)

/usr/include/glib-2.0/gio/ginitable.h

正式地,

/usr/include/glib-2.0/gio/ginitable.h:84:58: error: identifier "and" is a special operator name in C++ [-Werror=c++-compat]
 GLIB_DEPRECATED_IN_2_54_FOR(g_object_new_with_properties and g_initable_init)

我该如何解决这个问题?

【问题讨论】:

  • 不要使用-Werror?

标签: c++ c gcc cmake


【解决方案1】:

除了您当前的编译标志之外,不要使用-Werror,或者使用-Wno-error=c++-compat

一般来说,无条件的-Werrora bad idea。最好有选择地提升对错误的警告,例如-Werror=return-type。否则,您的项目必然无法使用其他编译器甚至当前编译器的较新版本进行编译。

【讨论】:

    【解决方案2】:

    除了添加@Ruslan 建议的标志之外,还可以考虑filing a bug report against GTK。虽然使用 and 作为标识符确实是有效的 C,但这是一个非常糟糕的主意,可以通过将名称更改为 and_conjunction 或其他名称来轻松避免。

    做前者将为解决问题。做后者可能会解决每个人的问题...

    【讨论】:

      猜你喜欢
      • 2018-05-12
      • 2012-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多