我使用以下方法在OSX10.10.5上安装了protobuf:
brew install protobuf
我也通过brew安装安装了g++-5,但是已经有一段时间了。为什么这不能用g++编译呢?
失败的命令是:
g++-5 -g -O2 -L/usr/local/Cellar/protobuf/2.6.1/lib -lprotobuf -D_THREAD_SAFE -o main main.o 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 ...
我只是在测试。我没有理由不在osx上使用clang++。我只是好奇。
发布于 2016-03-02 21:13:25
这是因为clang,g++-5和g++-4.x的ABI不同。您首先需要用g++-5重新编译protobuf本身,然后再用-lprotobuf将其链接到您的程序。
https://stackoverflow.com/questions/35758073
复制相似问题