简体   繁体   中英

protobuf will not compile on osx when using g++-5

See the following sample project based on the c++ tutorial on protobuf .

https://github.com/cskeeters/protobuf_addressbook

I installed protobuf on osx 10.10.5 using:

brew install protobuf

I installed g++-5 via brew install also, but it's been a while. Why won't this won't compile with g++?

The command that fails is:

g++-5 -g -O2 -L/usr/local/Cellar/protobuf/2.6.1/lib -lprotobuf -D_THREAD_SAFE -o main main.o addressbook.pb.o

The result is: 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 ...

I'm just testing. I have no reason not to use clang++ on osx. I'm just curious.

It is because different ABI for clang, g++-5 and g++-4.x. You need first to recompile protobuf itself with g++-5, and only then link it to your program with -lprotobuf .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM