compilation of protobuf fails with D_GLIBCXX_USE_CXX11_ABI=0

1.7k views Asked by At

I am running ubuntu 16.04 with gcc.

My q.ccp file is

#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/generated_message_reflection.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/descriptor.h>

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

    google::protobuf::Message* msg;


    const google::protobuf::Descriptor* message_desc = msg->GetDescriptor();


    const google::protobuf::FieldDescriptor * fd_name = message_desc->FindFieldByName("name");


    return 0;
}

command used for compilation:

g++ -D_GLIBCXX_USE_CXX11_ABI=0 q.cpp -L/usr/lib/x86_64-linux-gnu /usr/local/lib/libprotobuf.a -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:

/tmp/cciGJPqq.o: In function `main':
q.cpp:(.text+0x5f): undefined reference to `google::protobuf::Descriptor::FindFieldByName(std::string const&) const'
collect2: error: ld returned 1 exit status

But when I leave the -D_GLIBCXX_USE_CXX11_ABI=0 option, I get no compile error. But the problem is that I running the executable on different system which require compilation with this option for the program to run.

1

There are 1 answers

0
r11 On

If your compilation succeeds only with D_GLIBCXX_USE_CXX11_ABI=0, then you may be using a shared library (libprotobuf) that is precompiled using the same or using an older ABI, like gcc 4.8.

I would check the g++ version. It may be > 5, which would have the newer ABI.