c++ - 使用 g++-5 时,protobuf 不会在 osx 上编译

标签 c++ macos gcc protocol-buffers

请参阅以下基于 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/

相关文章:

c++ - 如何避免获取标准库函数地址时的非标准行为

c++ - 更改 Qt 布局中的调整大小行为

c - rand() 在 OSX 上是否返回零?

ruby-on-rails - OS X Lion 升级后捆绑更新和安装失败 - Rails 3

gcc - rpath 的正确用法(相对与绝对)

c++ - boost 多边形差异返回交集

c++ - 在 CLION 中使用 MSYS2 安装的库

objective-c - 在 Mac OS X 上将命令行应用程序转换为 Cocoa GUI 应用程序?

gcc - gcc 的 -mtune=generic 以哪个 cpu 为目标?

c - gcc 使用 malloc 进行内存对齐