Protocol buffers protobuf编译失败,D_GLIBCXX_USE_cx11_ABI=0

Protocol buffers protobuf编译失败,D_GLIBCXX_USE_cx11_ABI=0,protocol-buffers,undefined-reference,protoc,Protocol Buffers,Undefined Reference,Protoc,我正在用gcc运行ubuntu16.04 我的q.ccp文件是 #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&g

我正在用gcc运行ubuntu16.04

我的
q.ccp
文件是

#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;
}
protoc--version
返回:
2.2.0

gcc——版本

编译错误:

/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

但是当我离开
-D\u GLIBCXX\u USE\u cx11\u ABI=0
选项时,我没有得到编译错误。但问题是,我在不同的系统上运行可执行文件,这些系统需要使用此选项编译程序才能运行

如果您的编译仅在D_GLIBCXX_USE_cx11_ABI=0的情况下成功,那么您可能正在使用一个共享库(libprotobuf),该库使用相同的或较旧的ABI进行预编译,如gcc 4.8


我会检查g++版本。它可能大于5,这将具有较新的ABI。

如果您的编译仅在D_GLIBCXX_USE_cx11_ABI=0的情况下成功,那么您可能正在使用一个共享库(libprotobuf),该库使用相同的ABI或使用较旧的ABI进行预编译,如gcc 4.8


我会检查g++版本。可能是>5,这将有更新的ABI。

可能是@Danh的副本,来吧,至少阅读完整的问题。你真的是认真的吗?我不会改变我的决定,事实是g++已经做了ABI更改,你的程序需要用与你的库相同的ABI进行编译,在链接的问题中已经指出了这一点。你的protobuf安装在
/usr/local
,似乎是手工编译和安装的,你需要用相同的@Danh来编译这两个问题,拜托,至少要读完整的问题。你真的是认真的吗?我不会改变我的决定,事实是g++已经做了ABI更改,你的程序需要用与你的库相同的ABI进行编译,在链接的问题中已经指出了这一点。你的protobuf安装在
/usr/local
,似乎是手工编译和安装的,您需要使用相同的ABI编译它们
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.
/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