在 Mac 上的 Qt 项目中包含 protobuf3 headers

including protobuf3 headers in Qt project on Mac

如标​​题所示,我正在尝试在 Qt 中编译一个简单的项目,该项目利用 addressbook.pb.h/addressbook.pb.cc 中生成的文件 google C++ 用户的 protobuf3 教程。这是我的 .pro 文件

#-------------------------------------------------
#
# Project created by QtCreator 2016-11-07T10:33:12
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = prototest
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp \
    ../protobuf/examples/addressbook.pb.cc

HEADERS  += mainwindow.h \
    ../protobuf/examples/addressbook.pb.h

FORMS    += mainwindow.ui

INCLUDEPATH += /usr/local/Cellar/protobuf/3.1.0/include

LIBS += /usr/local/Cellar/protobuf/3.1.0

不幸的是,这抛出

:-1: error: can't map file, errno=22 file '/usr/local/Cellar/protobuf/3.1.0' for architecture x86_64

我卡在这一点上了。任何帮助将不胜感激。我已经能够使用 Xcode8 编译和 运行 完全相同的 (addressbook.*) 文件。

已解决:将以下内容添加到 .pro 文件

macx: LIBS += -L$$PWD/../../../usr/local/Cellar/protobuf/3.1.0/lib/ -lprotobuf.11

INCLUDEPATH += $$PWD/../../../usr/local/Cellar/protobuf/3.1.0/include
DEPENDPATH += $$PWD/../../../usr/local/Cellar/protobuf/3.1.0/include

我应该补充一下我是如何得出这个答案的。右键单击您的项目和 select "Add Library->External Library"、select 您的平台并输入您要添加的特定 (不是路径),以及您的包含路径(它给你的选项表明了这一点)。 Qt 将生成代码并自动将其添加到您的 .pro 文件中。