0

我正在尝试使用 wxWidgets 3.0 库编译以下代码:

foo.h

#ifdef __GNUC__
  #include <wx/version.h>

  #if wxMAJOR_VERSION >= 3
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wdeprecated-declarations" //< I'm trying to disable warning
  #endif // wxMAJOR_VERSION >= 3

#endif // __GNUC__

#ifdef HAVE_VARIADIC_MACROS
  #undef HAVE_VARIADIC_MACROS //< this macro redefines in wx.h
#endif // HAVE_VARIADIC_MACROS

#include <wx/wx.h> //< deprecated constructor defined here

#ifdef __GNUC__
  #pragma GCC diagnostic pop
#endif // __GNUC__

foo.cpp

#include "foo.h"
....
some_menu = new wxMenuItem( ... ); //< deprecated constructor

文件wx/menuitem.h 代码中定义的构造函数:

#if WXWIN_COMPATIBILITY_2_8 //< defined
    // compatibility only, don't use in new code
    wxDEPRECATED_CONSTRUCTOR(
    wxMenuItem(wxMenu *parentMenu,
               int id,
               const wxString& text,
               const wxString& help,
               bool isCheckable,
               wxMenu *subMenu = NULL)
    );
#endif

使用 gcc 5.4.0、Ubuntu 16.04 x86_64 编译:

    g++ -o foo.os -c -I/usr/lib/x86_64-linux-gnu/wx/include/gtk2-unicode-3.0 -I/usr/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -g3 -Wall -Werror
...
foo.cpp:83:109: error: 'wxMenuItem::wxMenuItem(...)' is deprecated [-Werror=deprecated-declarations]

我该如何解决?

4

1 回答 1

0

显而易见且最好的解决方案是停止使用已弃用的 ctor,这很简单,为什么不呢?

否则,我认为(但我没有测试它)你也可以让它与#pragmas 一起工作,但你需要使用这个 ctor 将它们放在你的代码周围,因为这是生成警告的地方,而不是在宣言。

最后,为了完整起见,您也可以删除-Werror并接受警告,但这当然不是最佳选择。

于 2016-12-16T15:49:53.437 回答