【问题标题】:C++ Protobuf Error google::protobuf::internal::kEmptyString ErrorC++ Protobuf 错误 google::protobuf::internal::kEmptyString 错误
【发布时间】:2016-04-01 15:29:40
【问题描述】:

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

/tmp/ccKgczB9.o:TickData.pb.cc:(.text+0x444): 未定义引用 google::protobuf::internal::kEmptyString' /tmp/ccKgczB9.o:TickData.pb.cc:(.text+0x4a9): undefined reference to google::protobuf::internal::kEmptyString' /tmp/ccKgczB9.o:TickData.pb.cc:(.text+0x4c4): 未定义的引用 google::protobuf::internal::kEmptyString' /tmp/ccKgczB9.o:TickData.pb.cc:(.text+0x4de): undefined reference to google::protobuf::internal::kEmptyString' /tmp/ccKgczB9.o:TickData.pb.cc:(.text+0x502): 未定义的引用 google::protobuf::internal::kEmptyString' /tmp/ccKgczB9.o:TickData.pb.cc:(.text+0x53c): more undefined references togoogle::protobuf::internal::kEmptyString' 跟随 /tmp/ccKgczB9.o:TickData.pb.cc:(.text$_ZN6google8protobuf8internal10WireFormat16VerifyUTF8StringEPKciNS2_9OperationE[__ZN6google8protobuf8internal10WireFormat16VerifyUTF8StringEPKciNS2_9OperationE]+0x1b): 未定义的引用 `google::protobuf::internal::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 但仍然是同样的错误。

任何指针都会有所帮助。

【问题讨论】:

  • 请显示您使用的编译器命令行。 (我的猜测是它缺少 -lprotobuf 标志。)
  • g++ -g -L"/cygdrive/d/Softwares/protobuf-2.6.1/src/.libs" ../proto/TickData.pb.cc main.cpp -std=c+ +11 -lprotobuf

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


【解决方案1】:

我确实找到了出路。

我需要首先使用 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

【讨论】:

    猜你喜欢
    • 2013-04-14
    • 2022-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    相关资源
    最近更新 更多