![](/img/trans.png)
[英]fatal error: google/protobuf/port_def.inc: No such file or directory #include <google/protobuf/port_def.inc>
[英]QT 5.7 - google/protobuf file not found - include PATH error
我試圖在OSX上使用QT創建者4.0.3在QT 5.7(clang 7.0)中使用google protobuf 2.6,但運氣不佳。
.pro文件具有
LIBS += `pkg-config --cflags -- libs protobuf`
包括protobuf庫。
在我使用原始文件生成的頭文件中,包含以下行
#include <google/protobuf/stubs/common.h>
這會產生一個編譯器錯誤
error: 'google/protobuf/stubs/common.h' file not found
QT使用pro文件中的LIBS + =命令找到了protobuf軟件包,而我在其中找到了未找到的頭文件
/Users/<username>/Qt/5.7/Src/qtwebengine/src/3rdparty/chromium/third_party/protobuf/src/google/protobuf/stubs
和
/usr/local/include/google/protobuf/stubs/common.h
我使用macports安裝了protobuf。
頭文件自動完成,因此QT知道它在哪里,所以我不確定如何處理找不到文件錯誤。
任何幫助,不勝感激。
謝謝。
編輯:
我認為問題是qt路徑未包含在/ usr / local /中,因此我可以找到protobuf包,但找不到任何頭文件(即使它是自動完成的)。 如何使用capitain在QT中添加到PATH?
編輯2:項目文件
#-------------------------------------------------
#
# Project created by QtCreator 2016-07-13T12:13:47
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = testexample
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
../../../protobuf/message.pb.cc
QT_CONFIG -= no-pkg-config
HEADERS += mainwindow.h \
../../../protobuf/message.pb.h
FORMS += mainwindow.ui
RESOURCES += \
resources.qrc
LIBS += `pkg-config --cflags -- libs protobuf`
在Windows / Linux / Mac中將Protobuf 2.4與Qt 5.7一起使用。 下載Protobuf 2.4並使用您正在使用的編譯器進行編譯(在Windows上使用MSVC / MinGW,在Linux上使用gcc,在Mac OS上使用clan)。 並編輯您的.pro文件。 我的.pro配置使用以下步驟:
加載已編譯的庫以進行調試/發布模式:
#For Windows
win32 {
CONFIG(debug, release|debug) {
win32:LIBS += -llibprotobuf-debug
} else {
win32:LIBS += -llibprotobuf
}
}
#For linux
!win32:LIBS += -lprotobuf
包含所有protobuf源代碼的路徑:
win32:INCLUDEPATH += "..\\...\\directoty_protobuf\\src"
它對我來說很好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.