弃用通知使用 GTKMM 和 C++11 进行构建

Deprecation notices building using GTKMM with C++11

我正在尝试将 GTKMM 与一个使用 C++11 功能的项目一起使用。 问题是显然 C++11 弃用了该语言的某些部分,而 GTKMM 似乎正在使用这些部分。

有没有什么方法可以去除这些消息,同时为我的代码保留有用的编译器警告?

Linux 上的编译器是 GCC 5.2。这些是我正在谈论的通知:

In file included from /usr/include/glibmm-2.4/glibmm/wrap.h:23:0,
                 from /usr/include/glibmm-2.4/glibmm/containerhandle_shared.h:26,
                 from /usr/include/glibmm-2.4/glibmm/arrayhandle.h:23,
                 from /usr/include/glibmm-2.4/glibmm.h:91,
                 from /usr/include/gtkmm-3.0/gtkmm.h:87,
                 from test.cpp:1:
/usr/include/glibmm-2.4/glibmm/objectbase.h:215:13: warning: ‘template<class> class std::auto_ptr’ is deprecated [-Wdeprecated-declarations]
 static std::auto_ptr<Threads::Mutex> extra_object_base_data_mutex;
             ^
In file included from /usr/include/c++/5.2.0/memory:81:0,
                 from /usr/include/glibmm-2.4/glibmm/objectbase.h:32,
                 from /usr/include/glibmm-2.4/glibmm/wrap.h:23,
                 from /usr/include/glibmm-2.4/glibmm/containerhandle_shared.h:26,
                 from /usr/include/glibmm-2.4/glibmm/arrayhandle.h:23,
                 from /usr/include/glibmm-2.4/glibmm.h:91,
                 from /usr/include/gtkmm-3.0/gtkmm.h:87,
                 from test.cpp:1:
/usr/include/c++/5.2.0/bits/unique_ptr.h:49:28: note: declared here template<typename> class auto_ptr;

如果编译器参数有问题,这里是CMakeLists(从OpenCV项目中重用,如果文件有问题请告知):

cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
list( APPEND CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS} -g -ftest-coverage -fprofile-arcs -libs")

project( interface )
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTKMM REQUIRED gtkmm-3.0)
include_directories(${GTKMM_INCLUDE_DIRS})
link_directories(${GTKMM_LIBRARY_DIRS})
add_definitions(${GTKMM_CFLAGS_OTHER})
add_executable( interface test.cpp )
target_link_libraries(interface ${GTKMM_LIBRARIES})

只是一个肮脏的 hack(因为可能 auto_ptr 在 GTKMM 中的使用是有问题的,所以你想向 GTKMM 报告错误);你可以使用一些 diagnostic pragmas 并将
#include <gtkmm.h> 替换为

//untested code
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#include <gtkmm.h>
#pragma GCC diagnostic warning  "-Wdeprecated-declarations"

但是 auto_ptr 在 C++11 中确实被弃用了,我不确定它是否与你的 C++11 标准库混合得很好。 (也许使用 Qt5 instead of GtkMM might be reasonable, since GtkMM might not be maintained for long, however it seems to know 问题;否则希望并可能有助于改进 GtkMM)。

您可能还应该在测试中使用 valgrind

我们最近在 glibmm 中修复了这个问题: https://bugzilla.gnome.org/show_bug.cgi?id=748630#c11

因此,为您的构建修复它的最佳方法是尽可能更新您的 glibmm 和 gtkmm 版本。