Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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 see

    So once that happened I generated the pb file, which went fine without any problems using
    protoc.exe --cpp_out=. myproto.proto

    So 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 = app

    SOURCES += main.cpp
    MainWindow.cpp
    Map/Tile.cpp
    Protobufs/myproto.pb.cc
    Map/TileTest.cpp

    HEADERS += MainWindow.h
    Map/Tile.h
    Protobufs/myproto.pb.h
    Map/TileTest.h
    config.h

    FORMS += 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 to google::protobuf::DescriptorPool::generated_pool()' error: undefined reference togoogle::protobuf::DescriptorPool::FindFileByName(std::string const&) const'
    error: undefined reference to google::protobuf::DescriptorPool::FindFileByName(std::string const&) const' error: undefined reference togoogle::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.


  • Lifetime Qt Champion

    Hi,

    Just a wild guess, are you using compatible compilers for all builds ?



  • Wow, that worked!

    Once things have been compiled into an .exe, I don't need to carry around the protobuf library since it's static library right?


  • Lifetime Qt Champion

    That's correct yes


Log in to reply