[英]protobuf will not compile on osx when using g++-5
See the following sample project based on the c++ tutorial on protobuf . 请参阅以下基于protobuf的c ++教程的示例项目。
https://github.com/cskeeters/protobuf_addressbook https://github.com/cskeeters/protobuf_addressbook
I installed protobuf on osx 10.10.5 using: 我在osx 10.10.5上使用以下命令安装了protobuf:
brew install protobuf
I installed g++-5 via brew install also, but it's been a while. 我也通过brew install安装了g ++-5,但是已经有一段时间了。 Why won't this won't compile with g++?
为什么不能用g ++编译?
The command that fails is: 失败的命令是:
g++-5 -g -O2 -L/usr/local/Cellar/protobuf/2.6.1/lib -lprotobuf -D_THREAD_SAFE -o main main.o addressbook.pb.o
The result is: Undefined symbols for architecture x86_64: "google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&))", referenced from: tutorial::protobuf_AddDesc_addressbook_2eproto() in addressbook.pb.o ...
结果是:
Undefined symbols for architecture x86_64: "google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&))", referenced from: tutorial::protobuf_AddDesc_addressbook_2eproto() in addressbook.pb.o ...
I'm just testing. 我正在测试。 I have no reason not to use clang++ on osx.
我没有理由不在osx上使用clang ++。 I'm just curious.
我只是好奇。
It is because different ABI for clang, g++-5 and g++-4.x. 这是因为clang,g ++-5和g ++-4.x的ABI不同。 You need first to recompile protobuf itself with g++-5, and only then link it to your program with
-lprotobuf
. 您首先需要使用g ++-5重新编译protobuf本身,然后才使用
-lprotobuf
将其链接到您的程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.