2016-12-22 9 views
1

gcc로 우분투 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- 외부 기호 오류 및 어떻게해야합니까 - 수정) – Danh

+0

@ 대장, 자, 사람, 적어도 전체 질문을 읽어보십시오. 너 정말 진심이야? – v78

+0

나는 내 결정을 바꾸지 않을 것이다. g ++은 ABI를 변경 시켰고, 당신의 프로그램은 당신의 라이브러리와 같은 ABI로 컴파일 될 필요가있다. – Danh

답변

0

컴파일이 D_GLIBCXX_USE_CXX11_ABI = 0으로 만 성공한 경우 gcc 4.8과 같이 이전 ABI를 사용하여 사전 컴파일 된 공유 라이브러리 (libprotobuf)를 사용 중일 수 있습니다.

g ++ 버전을 확인합니다. 새로운 ABI를 보유하게되면 5보다 클 수 있습니다.