请参阅以下基于 c++ tutorial 的示例项目在 protobuf .
https://github.com/cskeeters/protobuf_addressbook
我使用以下方法在 osx 10.10.5 上安装了 protobuf:
brew install protobuf
我也通过 brew install 安装了 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++。我只是好奇。
最佳答案
这是因为 clang、g++-5 和 g++-4.x 的 ABI 不同。您需要先使用 g++-5 重新编译 protobuf 本身,然后才使用 -lprotobuf
将其链接到您的程序。
关于c++ - 使用 g++-5 时,protobuf 不会在 osx 上编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35758073/