Using google protobuf with Qt Creator
-
Hi I am relatively new at this but I wanted to use Google's protobufs for my project.
I am using Win7.
So I used cygwin and did
./configure --enable-static --disable-shared - to create static lbirary.
make - to make
make check - all tests passed
make install - no errors that I could seeSo once that happened I generated the pb file, which went fine without any problems using
protoc.exe --cpp_out=. myproto.protoSo after that I went and started a new Qt Widget project.
I added existing files myproto.pb.cc and myproto.pb.h along with the config.h that was generated when I ran configure.This is what I have in my pro file. Qmake works fine with no error appearing.
@#-------------------------------------------------Project created by QtCreator 2014-01-04T16:16:27
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = TestProto
TEMPLATE = appSOURCES += main.cpp
MainWindow.cpp
Map/Tile.cpp
Protobufs/myproto.pb.cc
Map/TileTest.cppHEADERS += MainWindow.h
Map/Tile.h
Protobufs/myproto.pb.h
Map/TileTest.h
config.hFORMS += MainWindow.ui
LIBS += -LC:/cygwin64/usr/local/lib -lprotobuf
INCLUDEPATH += C:/cygwin64/usr/local/include
@However when I try to build it has the following error messages (put only 4 out of 200+):
@error: undefined reference togoogle::protobuf::DescriptorPool::generated_pool()' error: undefined reference to
google::protobuf::DescriptorPool::FindFileByName(std::string const&) const'
error: undefined reference togoogle::protobuf::DescriptorPool::FindFileByName(std::string const&) const' error: undefined reference to
google::protobuf::internal::LogMessage::LogMessage(google::protobuf::LogLevel, char const*, int)'@Any idea on what I am doing wrong?
I have searched for the answer but other people seem to be able to compile their code fine when they do it like this.
-
Hi,
Just a wild guess, are you using compatible compilers for all builds ?
-
That's correct yes
-
@VimHar said in Using google protobuf with Qt Creator:
Except lptotobuf im using llibprotouf
How do you link libprotobuf?
-
-
@jsulm Yes as stated I have these files in lib folder of the path specified,
libprotobuf.lib , libprotobuf-lite.lib , libprotoc.libMy .pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
INCLUDEPATH += C:\vcpkg\installed\x64-windows\include\
LIBS += -LC:/vcpkg/installed/x64-windows/lib/ -lprotobuf
SOURCES +=
main.cpp
mainwindow.cpp
m.pb.ccHEADERS +=
mainwindow.h
m.pb.hFORMS +=
mainwindow.ui -
-
@VimHar
There have been inconsistencies in the spellings of what you have typed in your various posts. Why don't you try:LIBS += C:\vcpkg\installed\x64-windows\lib\libprotobuf.lib
Please use copy & paste of above line. If you get error please copy & paste exact text back here.
-
@JonB said in Using google protobuf with Qt Creator:
LIBS += C:\vcpkg\installed\x64-windows\lib\libprotobuf.lib
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
INCLUDEPATH += C:\vcpkg\installed\x64-windows\include\
LIBS += C:\vcpkg\installed\x64-windows\lib\libprotobuf.lib
SOURCES +=
main.cpp
mainwindow.cpp
m.pb.ccHEADERS +=
mainwindow.h
m.pb.hFORMS +=
mainwindow.uiSorry for the same. Even then Im getting the same undefined error faced by the actual questioner.
i.e "undefined reference to `google::protobuf::internal::AssignDescriptors(google::protobuf::internal::DescriptorTable const*, bool)'' -
@VimHar said in Using google protobuf with Qt Creator:
Even then Im getting the same undefined error faced by the actual questioner.
i.e "undefined reference to `google::protobuf::internal::AssignDescriptors(google::protobuf::internal::DescriptorTable const*, bool)''Now I do not understand, because this is not the same error at all as you said you were having. You said you got one of:
. :-1: error: cannot find -lprotobuf
Cannot find llibprotouf.libThese errors mean it could not find the library file to link with --- which is why I wanted to get you to type in the full path --- where the error now is that the library file is found, but you have an unresolved reference. Quite different kinds of error.
I think/suspect the lib file is being found but is the wrong version or built with the wrong compiler or something like that.... Please start by answering @jsulm's question with your best information.
-
@VimHar said in Using google protobuf with Qt Creator:
Is this the problem??
Probably.
There should be a linker warning in the build log. -
@VimHar said in Using google protobuf with Qt Creator:
I used vcpkg for installing protobuf and Qt uses MinGw64.
I don't know what "vcpkg" is (MSVC??) but it sounds like a different compiler/linker. MinGW library files end in
.a
not.lib
, maybe that is the cause of the "cannot find library" messages? In any case you need to use the smae compiler/linker for everything.