当前位置: 首页 > 知识库问答 >
问题:

无法从google协议缓冲区编译示例

常朗
2023-03-14

我搜索其他主题,但它们对我没有帮助=(。在我的工作服务器上,我没有sudo特权,所以我安装PB时使用

./配置--prefix=/home/用户名/本地

然后我用“人”例子创建源文件,并用协议成功编译。

我没有pkg信息=(。我尝试用

g-I/home/username/local/include-L/home/username/local/lib-lprotobuf-lpthread main。cpp人员。pb。复写的副本

然后有10亿个模拟误差,即。

人pb。cc:(.text 0x4cf):对“google::protobuf::internal::kEmptyString”的未定义引用

我认为,这是链接的问题,但如何解决呢?

echo$LD\u LIBRARY\u路径/主页/用户名/本地/库

在main.cpp:

#include "person.pb.h"
...

谢谢。

共有3个答案

别俊誉
2023-03-14

还有一个相当普遍的问题,它不仅适用于链接protobuf,还适用于其他库。既然这是我的问题,我会把解决方案放在这里,也许有人会觉得它有用。

确保您正在尝试链接到具有相同ABI的库。C ABI在GCC 4.7.0中已更改。因此,您无法链接使用GCC编译的库

这个问题可以通过planty linkage抱怨std::basic\u string和std::list来识别,因为这是C中最有前途的ABI更改。我的链接器尖叫如下:

    /bincrafters/stable/package/c0c1ef10e3d0ded44179e28b669d6aed0277ca6a/lib  -L/home/adam/.conan/data/libpcap/1.8.1/bincrafters/stable/package/0a813c597d519ec14c71192b99d7de0a92bbc1c3/lib  -L/home/adam/.conan/data/zmq/4.2.2/bincrafters/stable/package/0144a3b0aceb8edb5e63295c432a8de8020ab1b7/lib  -L/home/adam/.conan/data/libsodium/1.0.16/bincrafters/stable/package/db2ca884c9793e0b0fb54ec3f846326d1addacc8/lib -Wl,-rpath,/hoar, std::char_traits<char>, std::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)'
CMakeFiles/NetworkMonitor.dir/addressbook.pb.cc.o: In function `tutorial::Person_PhoneNumber::InternalSerializeWithCachedSizesToArray(unsigned char*) const':
/home/adam/.conan/data/protobuf/3.9.1/bincrafters/stable/package/053ea29eb0edc6b1695c893b738a971110c756fd/include/google/protobuf/wire_format_lite.h:1673: undefined reference to `google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned char*)'
/home/adam/.conan/data/protobuf/3.9.1/bincrafters/stable/package/053ea29eb0edc6b1695c893b738a971110c756fd/include/google/protobuf/wire_format_lite.h:1673: undefined reference to `google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned char*)'
CMakeFiles/NetworkMonitor.dir/addressbook.pb.cc.o: In function `google::protobuf::internal::GetEmptyStringAlreadyInited[abi:cxx11]()':
/home/adam/.conan/data/protobuf/3.9.1/bincrafters/stable/package/053ea29eb0edc6b1695c893b738a971110c756fd/include/google/protobuf/message_lite.h:153: undefined reference to `google::protobuf::internal::fixed_address_empty_string[abi:cxx11]'
CMakeFiles/NetworkMonitor.dir/addressbook.pb.cc.o: In function `google::protobuf::internal::WireFormatLite::ReadString(google::protobuf::io::CodedInputStream*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)':
/home/adam/.conan/data/protobuf/3.9.1/bincrafters/stable/package/053ea29eb0edc6b1695c893b738a971110c756fd/include/google/protobuf/wire_format_lite.h:880: undefined reference to `google::protobuf::internal::WireFormatLite::ReadBytes(google::protobuf::io::CodedInputStream*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)'
CMakeFiles/NetworkMonitor.dir/addressbook.pb.cc.o:(.data.rel.ro._ZTVN8tutorial11AddressBookE[_ZTVN8tutorial11AddressBookE]+0x20): undefined reference to `google::protobuf::Message::GetTypeName[abi:cxx11]() const'
CMakeFiles/NetworkMonitor.dir/addressbook.pb.cc.o:(.data.rel.ro._ZTVN8tutorial11AddressBookE[_ZTVN8tutorial11AddressBookE]+0x58): undefined reference to `google::protobuf::Message::InitializationErrorString[abi:cxx11]() const'
CMakeFiles/NetworkMonitor.dir/addressbook.pb.cc.o:(.data.rel.ro._ZTVN8tutorial6PersonE[_ZTVN8tutorial6PersonE]+0x20): undefined reference to `google::protobuf::Message::GetTypeName[abi:cxx11]() const'
CMakeFiles/NetworkMonitor.dir/addressbook.pb.cc.o:(.data.rel.ro._ZTVN8tutorial6PersonE[_ZTVN8tutorial6PersonE]+0x58): undefined reference to `google::protobuf::Message::InitializationErrorString[abi:cxx11]() const'
CMakeFiles/NetworkMonitor.dir/addressbook.pb.cc.o:(.data.rel.ro._ZTVN8tutorial18Person_PhoneNumberE[_ZTVN8tutorial18Person_PhoneNumberE]+0x20): undefined reference to `google::protobuf::Message::GetTypeName[abi:cxx11]() const'
make[2]: *** [bin/N

在我为conan定义了一个概要文件并链接到使用相同版本的C ABI编译的库之后,这个问题就消失了。

訾渝
2023-03-14

库链接标志位于编译器参数的末尾:

g-I/home/username/local/include-L/home/username/local/lib main。cpp人员。pb。cc-lprotobuf-lpthread

梁丘招
2023-03-14

将库放在末尾:

/home/username/local/include /home/username/local/libperson.pb.cc

GCC链接选项:

-llibrary
-l library
    Search the library named library when linking. 
    (The second alternative with the library as a separate argument
    is only for POSIX compliance and is not recommended.)

    It makes a difference where in the command you write this option;
    the linker searches and processes libraries and object files in the
    order they are specified.
    Thus, `foo.o -lz bar.o' searches library `z' after file foo.o but
    before bar.o. If bar.o refers to functions in `z', those functions
    may not be loaded.

此外,使用pthread而不是lpthread,因为pthread可以为预处理器和链接器设置标志。

 类似资料:
  • 问题内容: 我grep其他主题,但他们没有帮助我=(。在我的工作服务器上,我没有sudo特权,因此我使用 ./configure –prefix = / home /用户名/本地 然后,我用“ person”示例创建源文件,并使用protoc成功地对其进行编译。 我没有pkg-info =(。我尝试用 g ++ -I / home /用户名/本地/ include -L / home /用户名/本

  • 我正在学习关于协议缓冲区的google python教程,在编译器出现之前,我已经能够成功地完成所有工作。 https://developers.google.com/protocol-buffers/docs/pythontutorial 本教程内容如下: 现在运行编译器,指定源目录(应用程序的源代码所在的目录–如果不提供值,则使用当前目录)、目标目录(希望生成的代码所在的目录;通常与$SRC\

  • 问题内容: 我正在使用gSoap将旧式C 系统重构为SOA。我们遇到了一些性能问题(非常大的XML),因此我的领导要我看一下协议缓冲区。我做到了,它看起来非常酷(我们需要C 和Java支持)。但是协议缓冲区是仅用于序列化的解决方案,现在我需要将其发送到Java前端。从C ++和Java角度来看,我应该使用什么来通过HTTP(只是内部网络)发送那些序列化的内容? PS。另一个人试图加速我们的gSoa

  • 请注意:虽然这个问题特别提到了Dropwizard,但我相信任何有泽西/JAX-RS经验的人都应该能够回答这个问题,因为我可以想象Dropwizard只是在幕后遵循泽西/JAX-RS约定。 我有一个Dropwizard服务,它用JSON编写,工作非常出色。 现在我想将其切换为读/写二进制数据(以最小化网络带宽)。我看到了Dropwizard Protobuf库,但我对在Dropwizard中实现二

  • 我按照协议缓冲区的教程,我在编译时不断遇到不同的错误。我的addressbook.proto文件在中

  • 我正在使用Google Protocol Buffers向服务器发送消息。我对如何发送图像与如何接收图像感到困惑。有关详细信息,请参阅下面的代码,但我的问题是: 我需要base64_decode从未经过base64编码的返回字符串吗,因为它是使用char*和size发送的?也许Google Protocol Buffers处理了这个问题,但我在生成的类中找不到任何证据。 我可能在这里找到了答案,但