将 Google 的协议缓冲区添加到 Qt ;禁用编译器警告

Adding Google's protocol Buffer to Qt ; Disable Compiler Warnings

为了将 google 中的 protobuf 库添加到我的 Qt 项目中,我执行了以下步骤。我将 Windows 10Qt 5.6mingw32 编译器一起使用。

1 安装 protobuf

因此,我将带有 mingw 和 cd 的 MSYS 安装到 protobuf-3.0.0-beta-2 目录,其中我 运行 配置脚本 ./configure --prefix= 'cd /c/qt/Tools/mingw492_32/ ; pwd -W 确保在 Qt 编译器目录中安装 protobuf .后来我运行makemake install.

2 使用 protobuf 编译项目

现在我将包含路径 INCLUDEPATH += C:/qt/tools/mingw492_32/include 和库路径 LIBS += $$PWD/../protobuf-3.0.0-beta-2/src/libs/libprotobuf.a 添加到我的 Qt 项目文件中以使 google protobuf 可用。

编译我的项目成功,但我收到很多警告,因为 protobuf 库有很多未使用的参数/虚拟函数。有什么方法可以关闭从外部 protobuf 库获得的警告吗?

你需要告诉编译器protobuf headers 是系统headers。 -I 标志告诉编译器在哪里寻找 non-system headers,而 -isystem 给出包含系统 headers 的目录。系统 headers 不产生警告。但是 INCLUDEPATH 使用 -I.

而不是:

INCLUDEPATH += C:/qt/tools/mingw492_32/include

尝试:

QMAKE_CXXFLAGS += -isystem C:/qt/tools/mingw492_32/include