請參閱protobuf上c++ 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 ++。我只是好奇。
我已經驗證了,g ++ - 5可以在使用g ++ - 5編譯protobuf時使用。我不得不設置'DYLD_LIBRARY_PATH'來讓生成的二進制文件使用非brew庫。 –