0

I am running ubuntu 16.04 with gcc.

My q.ccp file is

#include <my_messages.pb.h>

int main(int argc, char **argv)
{

    google::protobuf::MyMessage* logged_msg_;

    return 0;
}

command used for compilation:

g++ -m64 -Wl,-O1 -L/usr/lib/x86_64-linux-gnu /usr/local/lib/libprotobuf.a my_messages.pb.cc q.cpp -lpthread

protoc --version returns: 2.2.0

gcc --version

gcc (Ubuntu 4.8.5-4ubuntu2) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

compile error starts with

undefined reference to `google::protobuf::internal::ExtensionSet::Clear()

and gives undefined reference error for every function of protocol buffers.

halfelf
  • 9,737
  • 13
  • 54
  • 63
v78
  • 2,803
  • 21
  • 44

1 Answers1

3

Order of arguments to GCC matters a lot (libraries should go after object files and source files). You probably want

g++ -Wall -m64 -O1 -g -L/usr/lib/x86_64-linux-gnu -L/usr/local/lib/ \
     my_messages.pb.cc q.cpp -lprotobuf -lpthread

(I would believe that -Wl,-O1 is wrong and useless, but I leave you to check that)

Take some time to read the GCC command options chapter of the documentation. You might want to (temporarily) use g++ -v instead of g++ in the command above to understand what is going on.

You probably should use GNU make for your build. See this example of Makefile for inspiration. Spend some time to read documentation of make.

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547