Protocol Buffers 的静态链接导致与现有符号发生冲突

Art*_*cik 5 c++ linux protocol-buffers onnx

我们正在尝试为 C++ 运行时实现协议缓冲区格式 (ONNX) 导入器。我们的运行时将由前端应用程序使用,前端应用程序也使用协议缓冲区模型。

当尝试执行同时运行前端和后端组件的进程时,我们看到错误指示符号名称conflicts with the existing symbol.

[libprotobuf ERROR google/protobuf/descriptor_database.cc:109] Symbol name "onnx.AttributeProto" conflicts with the existing symbol "onnx.AttributeProto".
[libprotobuf FATAL google/protobuf/descriptor.cc:1164] CHECK failed: generated_database_->Add(encoded_file_descriptor, size):
terminate called after throwing an instance of 'google::protobuf::FatalException'
 what():  CHECK failed: generated_database_->Add(encoded_file_descriptor, size):
Aborted (core dumped)
Run Code Online (Sandbox Code Playgroud)

有没有办法让两个组件(应用程序和共享对象)静态链接 PB 消息处理代码并在一个进程中注册相同的 Protobuf 符号?有没有办法告诉其他组件不要重新注册PB消息?

pos*_*nal 0

命名空间重整解决方案

Protocol Buffers 拥有一个基于.proto文件名的全局注册表。当两个软件尝试将相同的 PB 消息添加到此注册表时,您会遇到名称冲突。

解决此问题的一种方法是人为更改 PB 消息命名空间。您可以为 PB 消息定义不同的命名空间,并依靠 CMakefile 进行符号替换和重命名。

这是该onnx-tensorrt项目的一个示例:

https://github.com/onnx/onnx-tensorrt/blob/fa0964e8477fc004ee2f49ee77ffce0bf7f711a9/CMakeLists.txt#L92-L97