只使用Qt和附带的工具构建protobufs

Build protobufs only using Qt and tools shipped with it

本文关键字:工具 构建 protobufs Qt      更新时间:2023-10-16

我在win7上开发Qt应用程序(使用包含MinGW的Windows Qt发行版),我需要使用谷歌的协议缓冲区。所以我遵循了这个如何在Windows中使用MinGW构建Google's protobuf ?我已经成功地建立了它。

但是我有必要分别安装MinGW和MSYS来实现这一点。

是否有清洁方式如何在我的应用程序中构建protobufs只是使用Qt和它的工具链?

我们创建了一个新项目,并从protobuf中添加了文件。我可以给你我的。profile文件。然后我们将这个项目包含到我们的公共项目(子项目)

QT       -= gui
TARGET = protobuf
TEMPLATE = lib
CONFIG += staticlib
# DESTDIR
win32 {
    CONFIG(debug, debug|release): DESTDIR = ../bin/debug
    CONFIG(release, debug|release): DESTDIR = ../bin/release
}
unix {
    CONFIG(debug, debug|release): DESTDIR = ../bin_unix/debug
    CONFIG(release, debug|release): DESTDIR = ../bin_unix/release
}
INCLUDEPATH += ../protobuf
SOURCES += 
    google/protobuf/wire_format_lite.cc 
    google/protobuf/wire_format.cc 
    google/protobuf/unknown_field_set.cc 
    google/protobuf/text_format.cc 
    google/protobuf/service.cc 
    google/protobuf/repeated_field.cc 
    google/protobuf/reflection_ops.cc 
    google/protobuf/message_lite.cc 
    google/protobuf/message.cc 
    google/protobuf/generated_message_util.cc 
    google/protobuf/generated_message_reflection.cc 
    google/protobuf/extension_set_heavy.cc 
    google/protobuf/extension_set.cc 
    google/protobuf/dynamic_message.cc 
    google/protobuf/descriptor_database.cc 
    google/protobuf/descriptor.pb.cc 
    google/protobuf/descriptor.cc 
    google/protobuf/compiler/parser.cc 
    google/protobuf/compiler/importer.cc 
    google/protobuf/io/zero_copy_stream_impl_lite.cc 
    google/protobuf/io/zero_copy_stream_impl.cc 
    google/protobuf/io/zero_copy_stream.cc 
    google/protobuf/io/tokenizer.cc 
    google/protobuf/io/printer.cc 
    google/protobuf/io/gzip_stream.cc 
    google/protobuf/io/coded_stream.cc 
    google/protobuf/stubs/substitute.cc 
    google/protobuf/stubs/strutil.cc 
    google/protobuf/stubs/structurally_valid.cc 
    google/protobuf/stubs/once.cc 
    google/protobuf/stubs/common.cc
HEADERS += 
    google/protobuf/wire_format_lite_inl.h 
    google/protobuf/wire_format_lite.h 
    google/protobuf/wire_format.h 
    google/protobuf/unknown_field_set.h 
    google/protobuf/text_format.h 
    google/protobuf/service.h 
    google/protobuf/repeated_field.h 
    google/protobuf/reflection_ops.h 
    google/protobuf/message_lite.h 
    google/protobuf/message.h 
    google/protobuf/generated_message_util.h 
    google/protobuf/generated_message_reflection.h 
    google/protobuf/extension_set.h 
    google/protobuf/dynamic_message.h 
    google/protobuf/descriptor_database.h 
    google/protobuf/descriptor.pb.h 
    google/protobuf/descriptor.h 
    google/protobuf/compiler/parser.h 
    google/protobuf/compiler/importer.h 
    google/protobuf/io/zero_copy_stream_impl_lite.h 
    google/protobuf/io/zero_copy_stream_impl.h 
    google/protobuf/io/zero_copy_stream.h 
    google/protobuf/io/tokenizer.h 
    google/protobuf/io/printer.h 
    google/protobuf/io/gzip_stream.h 
    google/protobuf/io/coded_stream_inl.h 
    google/protobuf/io/coded_stream.h 
    google/protobuf/stubs/substitute.h 
    google/protobuf/stubs/strutil.h 
    google/protobuf/stubs/stl_util-inl.h 
    google/protobuf/stubs/once.h 
    google/protobuf/stubs/map-util.h 
    google/protobuf/stubs/hash.h 
    google/protobuf/stubs/common.h 
    config.h
# Turn off ALL warning for the project
win32:CONFIG += warn_off

另一种构建方法是使用这个项目:https://github.com/cjh1/protobuf,它不需要运行。/configure,但需要CMake构建系统,它可以与Qt自带的MinGW工具链集成。它目前只构建一个protobufs作为静态库(不是动态/共享),不安装头文件,但我希望最终这些功能将被内置。