2016-03-02 49 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庫。 –