C ++ Protobuf错误google :: protobuf :: internal :: kEmptyString错误

时间:2016-04-01 15:29:40

标签: c++ c++11 protocol-buffers

我在连接protobuf库时遇到问题。

  

/tmp/ccKgczB9.o:TickData.pb.cc :(。text + 0x444):未定义的引用   google::protobuf::internal::kEmptyString' /tmp/ccKgczB9.o:TickData.pb.cc:(.text+0x4a9): undefined reference to 谷歌:: protobuf的::内部:: kEmptyString”   /tmp/ccKgczB9.o:TickData.pb.cc:(.text+0x4c4):未定义的引用   google::protobuf::internal::kEmptyString' /tmp/ccKgczB9.o:TickData.pb.cc:(.text+0x4de): undefined reference to 谷歌:: protobuf的::内部:: kEmptyString”   /tmp/ccKgczB9.o:TickData.pb.cc:(.text+0x502):未定义的引用   google::protobuf::internal::kEmptyString' /tmp/ccKgczB9.o:TickData.pb.cc:(.text+0x53c): more undefined references to google :: protobuf :: internal :: kEmptyString'关注   /tmp/ccKgczB9.o:TickData.pb.cc:(.text$_ZN6google8protobuf8internal10WireFormat16VerifyUTF8StringEPKciNS2_9OperationE[__ZN6google8protobuf8internal10WireFormat16VerifyUTF8StringEPKciNS2_9OperationE]+0x1b):   未定义的引用   `谷歌:: protobuf的内部:: :: WireFormat :: VerifyUTF8StringFallback(CHAR   const *,int,google :: protobuf :: internal :: WireFormat :: Operation)'   collect2:错误:ld返回1退出状态

使用的语言:C ++ Protobuf版本:2.6.1

我已经在下面的链接上尝试了一些东西,但它没有用完:

Can't compile example from google protocol buffers

Undefined reference to google::protobuf::internal::empty_string_[abi:cxx11]

我是C ++的新手。我也尝试使用-std = c ++ 11编译protobuf,但仍然是同样的错误。

任何指针都会有所帮助。

1 个答案:

答案 0 :(得分:0)

我确实找到了出路。

我需要先为g ++使用-c选项并生成.o文件。然后再单独使用-o选项来生成可执行文件。

如下图所示:

g ++ -c -L / cygdrive / d / Workspace / CPP / Practice / .libs /../proto/TickData.pb.cc main.cpp -std = c ++ 11 -lprotobuf

g ++ -g -Wall TickData.pb.o main.o -o MarketData.o -std = c ++ 11 -lprotobuf