仅使用随附的Qt和工具构建protobufs

时间:2014-03-14 07:49:05

标签: c++ qt protocol-buffers

我正在Win 7上开发Qt应用程序(使用包含MinGW的Windows Qt发行版),我需要使用Google的协议缓冲区。所以我遵循了这个How to build Google's protobuf in Windows using MinGW?,我已经设法建立了它。

但是我需要单独安装MinGW和MSYS来实现这一目标。

有没有更清晰的方式如何使用Qt和它的工具链在我的应用程序中构建protobufs?

2 个答案:

答案 0 :(得分:2)

我们创建了新项目并从protobuf添加了文件。我可以给你我的.pro文件。 然后我们将这个项目包含在我们的共同项目(子目录)

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

答案 1 :(得分:0)

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