title: Issues compiling Qt project with Google Protocol Buffer
body: <p>I am building a network application with Qt and Protocol Buffer.  I have a server, which can be compiled successfully, and a Qt client, which cannot be compiled with Protocol Buffer.</p>
  
  <p>The server is built by running <code>make</code> on the following Makefile</p>
  
  <pre><code>PWD := $(shell pwd)
  CXX := g++
  
  LINKER := g++
  INCDIRS := -I. -I$(PWD)/lib -I$(PWD)/lib/protobuf-2.6.1/src 
  LIBDIRS := $(PWD)/lib/protobuf-2.6.1/src/.libs 
  LIBS := -l protobuf 
  CXXFLAGS := -std=c++11 -pthread -g #-Wall -Wextra 
  BUILD_DIR=build
  BIN := $(BUILD_DIR)/bin
  
  PROTO := $(shell bash -c "pwd")/lib/protobuf-2.6.1/src/protoc
  MODEL_DIR := model
  MODEL_BUILD_DIR := build
  BIN := $(BUILD_DIR)/bin
  MODELS := $(shell bash -c "cd $(MODEL_DIR) &amp;&amp; ls *.proto")
  MODELS_SRCFILES := $(patsubst %.proto, %.pb.cc, $(MODELS))
  MODELS_OBJFILES := $(addprefix $(MODEL_DIR)/$(MODEL_BUILD_DIR)/, $(patsubst %.cc,%.o,$(MODELS_SRCFILES)))
  INCDIRS += -I$(MODEL_DIR)/$(MODEL_BUILD_DIR)
  
  SERVER_DIR := server
  SERVER_SRCFILES := $(wildcard $(SERVER_DIR)/*.cpp) 
  SERVER_OBJFILES := $(addprefix $(BIN)/, $(patsubst %.cpp,%.o,$(SERVER_SRCFILES)))
  SERVER_BUILD := $(BUILD_DIR)/server
  
  CLIENT_DIR := client
  QMAKE := qmake
  
  LIB_DIR := lib
  LIB_SRCFILES := $(wildcard $(LIB_DIR)/*.cpp) 
  LIB_OBJFILES := $(addprefix $(BIN)/, $(patsubst %.cpp,%.o,$(LIB_SRCFILES)))
  
  .PHONY: init_dir clean client model 
  
  all: init_dir model $(SERVER_BUILD) 
  
  run:
      @export LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:$(LIBDIRS) &amp;&amp; ./build/server
  
  run_client:
      @export LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:$(LIBDIRS) &amp;&amp; ./build/client
  
  init_dir: 
      @mkdir -p $(BIN)/$(SERVER_DIR) $(BIN)/$(MODEL_DIR) $(MODEL_DIR)/$(MODEL_BUILD_DIR) $(BIN)/$(LIB_DIR) 
  
  model: $(addprefix, $(MODEL_DIR)/, $(MODELS))
      @cd $(MODEL_DIR) &amp;&amp; \
      for model in $(MODELS); do echo proto compiling $$model; \
      $(PROTO) -I=. --cpp_out=./$(MODEL_BUILD_DIR) $$model; done  &amp;&amp; \
      cd $(MODEL_BUILD_DIR) &amp;&amp; \
      for modelcc in $(MODELS_SRCFILES); do echo compiling $$modelcc; $(CXX) $(CXXFLAGS) $(INCDIRS) -c $$modelcc ; done
  
  $(SERVER_BUILD): $(LIB_OBJFILES) $(MODELS_OBJFILES) $(SERVER_OBJFILES) 
      $(LINKER) $^ -L $(LIBDIRS) $(LIBS) -o $@
  
  
  $(BIN)/$(SERVER_DIR)/%.o: $(SERVER_DIR)/%.cpp
      $(CXX) $(CXXFLAGS) $(INCDIRS) -c $&lt; -o $@
  
  $(BIN)/$(LIB_DIR)/%.o: $(LIB_DIR)/%.cpp
      $(CXX) $(CXXFLAGS) $(INCDIRS) -c $&lt; -o $@
  
  client:
      @cd $(CLIENT_DIR) &amp;&amp; $(QMAKE) &amp;&amp; $(MAKE) 
  
  clean:
      rm -rf $(BUILD_DIR) $(MODEL_DIR)/$(MODEL_BUILD_DIR)/*
  </code></pre>
  
  <p>The client Qt project uses this .pro:</p>
  
  <pre><code>QT       += core gui
  
  CONFIG += c++11
  
  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
  
  TARGET = client
  TEMPLATE = app
  
  SOURCES += main.cpp\
          mainwindow.cpp \
          ../model/build/main.model.pb.cc \
          ../model/build/guess.model.pb.cc \
          ../model/build/jack.model.pb.cc \
          ../model/build/system.model.pb.cc \
          changename.cpp
  
  
  HEADERS  += mainwindow.h \
      ../model/build/main.model.pb.h \
      ../model/build/guess.model.pb.h \
      ../model/build/jack.model.pb.h \
      ../model/build/system.model.pb.h \
  
  FORMS    += mainwindow.ui \
  
  DESTDIR=../build 
  OBJECTS_DIR=../build/bin/client
  MOC_DIR=../build/bin/client
  
  
  unix:!macx: LIBS += -L../lib/protobuf-2.6.1/src/.libs/ -lprotoc
  
  INCLUDEPATH += ../lib/protobuf-2.6.1/src/.libs   ../lib ../model/build/
  DEPENDPATH += ../lib/protobuf-2.6.1/src/.libs
  
  unix:!macx: PRE_TARGETDEPS += ../lib/protobuf-2.6.1/src/.libs/libprotoc.a
  </code></pre>
  
  <p>The four protoc generated files, i.e. <code>../model/build/*.model.pb.h</code>, is generated by <code>make model</code>.</p>
  
  <p>My issue is that running <code>make model</code> alone can successfully compile the protocol buffer implementation files.  But including them as <code>SOURCES</code> and compile them with <code>qmake</code> generated Makefile does not work.</p>
  
  <p>The error is as follow: </p>
  
  <pre><code>g++ -c -m64 -pipe -O2 -std=c++0x -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I. -I../lib/protobuf-2.6.1/src/.libs -I../lib -I../model/build -I/usr/include/qt5 -I/usr/include/qt5/QtWidgets -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I../build/bin/client -I. -o ../build/bin/client/main.o main.cpp
  In file included from mainwindow.h:6:0,
                   from main.cpp:1:
  ../model/build/main.model.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is
   #error This file was generated by a newer version of protoc which is
    ^
  ../model/build/main.model.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update
   #error incompatible with your Protocol Buffer headers.  Please update
    ^
  ../model/build/main.model.pb.h:14:2: error: #error your headers.
   #error your headers.
    ^
  In file included from ../model/build/main.model.pb.h:27:0,
                   from mainwindow.h:6,
                   from main.cpp:1:
  ../model/build/jack.model.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is
   #error This file was generated by a newer version of protoc which is
    ^
  ../model/build/jack.model.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update
   #error incompatible with your Protocol Buffer headers.  Please update
    ^
  ../model/build/jack.model.pb.h:14:2: error: #error your headers.
   #error your headers.
    ^
  In file included from ../model/build/main.model.pb.h:28:0,
                   from mainwindow.h:6,
                   from main.cpp:1:
  ../model/build/system.model.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is
   #error This file was generated by a newer version of protoc which is
    ^
  ../model/build/system.model.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update
   #error incompatible with your Protocol Buffer headers.  Please update
    ^
  ../model/build/system.model.pb.h:14:2: error: #error your headers.
   #error your headers.
    ^
  In file included from ../model/build/system.model.pb.h:28:0,
                   from ../model/build/main.model.pb.h:28,
                   from mainwindow.h:6,
                   from main.cpp:1:
  ../model/build/guess.model.pb.h:12:2: error: #error This file was generated by a newer version of protoc which is
   #error This file was generated by a newer version of protoc which is
    ^
  ../model/build/guess.model.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update
   #error incompatible with your Protocol Buffer headers.  Please update
    ^
  ../model/build/guess.model.pb.h:14:2: error: #error your headers.
   #error your headers.
    ^
  In file included from ../model/build/main.model.pb.h:27:0,
                   from mainwindow.h:6,
                   from main.cpp:1:
  ../model/build/jack.model.pb.h: In member function ‘void BlackJack::Request::clear_command()’:
  ../model/build/jack.model.pb.h:297:20: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
     if (command_ != &amp;::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
                      ^
  ../model/build/jack.model.pb.h: In member function ‘void BlackJack::Request::set_command(const string&amp;)’:
  ../model/build/jack.model.pb.h:308:20: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
     if (command_ == &amp;::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
                      ^
  ../model/build/jack.model.pb.h: In member function ‘void BlackJack::Request::set_command(const char*)’:
  ../model/build/jack.model.pb.h:316:20: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
     if (command_ == &amp;::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
                      ^
  ../model/build/jack.model.pb.h: In member function ‘void BlackJack::Request::set_command(const char*, size_t)’:
  ../model/build/jack.model.pb.h:324:20: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
     if (command_ == &amp;::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
                      ^
  ../model/build/jack.model.pb.h: In member function ‘std::string* BlackJack::Request::mutable_command()’:
  ../model/build/jack.model.pb.h:332:20: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
     if (command_ == &amp;::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
                      ^
  ../model/build/jack.model.pb.h: In member function ‘std::string* BlackJack::Request::release_command()’:
  ../model/build/jack.model.pb.h:340:20: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
     if (command_ == &amp;::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
                      ^
  ../model/build/jack.model.pb.h:344:45: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
       command_ = const_cast&lt; ::std::string*&gt;(&amp;::google::protobuf::internal::GetEmptyStringAlreadyInited());
                                               ^
  ../model/build/jack.model.pb.h: In member function ‘void BlackJack::Request::set_allocated_command(std::string*)’:
  ../model/build/jack.model.pb.h:349:20: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
     if (command_ != &amp;::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
                      ^
  ../model/build/jack.model.pb.h:357:45: error: ‘GetEmptyStringAlreadyInited’ is not a member of ‘google::protobuf::internal’
       command_ = const_cast&lt; ::std::string*&gt;(&amp;::google::protobuf::internal::GetEmptyStringAlreadyInited());
                                               ^
  </code></pre>
  
  <p>What could be the problem??</p>
  
  <p>Thanks for your help</p>