2016-12-22 5 views
1

gccでubuntu 16.04を実行しています。protobufのコンパイルがD_GLIBCXX_USE_CXX11_ABI = 0で失敗する

g++ -D_GLIBCXX_USE_CXX11_ABI=0 q.cpp -L/usr/lib/x86_64-linux-gnu /usr/local/lib/libprotobuf.a -lpthread 

protoc --versionリターン:

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; 
} 

コマンドである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. 

コンパイルエラー:

/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_GLIBCXX_USE_CXX11_ABI=0オプションを去るとき、私はコンパイルエラーを取得していません。しかし問題は、プログラムを実行するためにこのオプションでコンパイルが必要な異なるシステム上で実行可能ファイルを実行していることです。

+0

[定義されていない参照/未解決の外部シンボルエラーとは何ですか?どうすれば修正できますか?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-外部記号エラーと方法i-fix) – Danh

+0

@ダン、さようなら、完全な質問を少なくとも読んでください。あなたは本当に深刻ですか? – v78

+0

私は自分の意思決定を変更しません.g ++はABIを変更しました。あなたのライブラリは同じABIでコンパイルする必要があります。 – Danh

答えて

0

コンパイルがD_GLIBCXX_USE_CXX11_ABI = 0でしか成功しない場合は、gcc 4.8のように同じABIを使用してプリコンパイルされた共有ライブラリ(libprotobuf)を使用している可能性があります。

g ++のバージョンを確認します。それは> 5かもしれないが、これは新しいABIを持つだろう。

関連する問題