To avoid the affection of my other code, I wrote down this short snippet: packet.proto:
message packet { required uint32 var = 1; } And pb.cc: #include "packet.pb.h" int main() { GOOGLE_PROTOBUF_VERIFY_VERSION; google::protobuf::ShutdownProtobufLibrary(); return 0; } If I try to link with libc++, clang++ will complain like this error: $ clang++ -stdlib=libc++ -o pb pb.cc packet.pb.cc -lprotobuf Undefined symbols for architecture x86_64: "google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&))", referenced from: protobuf_AddDesc_packet_2eproto() in packet-q8y2hq.o "google::protobuf::DescriptorPool::FindFileByName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from: protobuf_AssignDesc_packet_2eproto() in packet-q8y2hq.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) But everything seems OK without libc++: $ clang++ -o pb pb.cc packet.pb.cc -lprotobuf $ otool -L pb pb: /usr/local/lib/libprotobuf.7.dylib (compatibility version 8.0.0, current version 8.0.0) /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0) Here are the versions of clang and protobuf: $ clang -v Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn) Target: x86_64-apple-darwin12.2.0 Thread model: posix $ brew info protobuf protobuf: stable 2.4.1 http://code.google.com/p/protobuf/ /usr/local/Cellar/protobuf/2.4.1 (62 files, 5.9M) * https://github.com/mxcl/homebrew/commits/master/Library/Formula/protobuf.rb And I also compiled the snippet on a Linux workstation on which clang and libc++ were installed. But no error was raised with libc++. $ /opt/llvm/bin/clang++ -stdlib=libc++ -o pb pb.cc packet.pb.cc -lprotobuf $ ldd pb linux-gate.so.1 => (0x005dd000) libprotobuf.so.7 => /usr/local/lib/libprotobuf.so.7 (0x0035c000) libc++.so.1 => /usr/lib/libc++.so.1 (0x00113000) libm.so.6 => /lib/libm.so.6 (0x0072d000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x006ea000) libc.so.6 => /lib/libc.so.6 (0x00a6c000) libpthread.so.0 => /lib/libpthread.so.0 (0x001b1000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x001cc000) librt.so.1 => /lib/librt.so.1 (0x002b7000) /lib/ld-linux.so.2 (0x008c3000) As you can see above, I built libc++ on Linux by using libstdc++ as the ABI layer. $ clang++ -v clang version 3.1 (tags/RELEASE_31/final 170526) Target: i386-pc-linux-gnu Thread model: posix libcxx$ svn info Path: . URL: http://llvm.org/svn/llvm-project/libcxx/trunk Repository Root: http://llvm.org/svn/llvm-project Repository UUID: 91177308-0d34-0410-b5e6-96231b3b80d8 Revision: 170542 Node Kind: directory Schedule: normal Last Changed Author: marshall Last Changed Rev: 170435 Last Changed Date: 2012-12-19 00:46:30 +0800 (Wed, 19 Dec 2012) Could anybody give some suggestion about this? -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To view this discussion on the web visit https://groups.google.com/d/msg/protobuf/-/LaxB-nG-dQEJ. To post to this group, send email to protobuf@googlegroups.com. To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.