2016-03-02 97 views
0

请参阅protobufc++ tutorial的示例项目。当使用g ++时,protobuf将无法在osx上编译 - 5

https://github.com/cskeeters/protobuf_addressbook

我使用安装在OSX 10.10.5的protobuf:

brew install protobuf

我安装了G ++ - 5通过BREW也安装,但它已经有一段时间。为什么不能用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 ++。我只是好奇。

回答

1

这是因为clang,g ++ - 5和g ++ - 4.x的ABI不同。您需要先使用g ++ - 5重新编译protobuf本身,然后才能使用-lprotobuf将其链接到您的程序。

+0

我已经验证了,g ++ - 5可以在使用g ++ - 5编译protobuf时使用。我不得不设置'DYLD_LIBRARY_PATH'来让生成的二进制文件使用非brew库。 –