gpt4 book ai didi

c++ - Protocol Buffers 的静态链接导致与现有符号的冲突

转载 作者:IT王子 更新时间:2023-10-29 00:43:23 36 4
gpt4 key购买 nike

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

当尝试执行同时运行前端和后端组件的进程时,我们看到错误表明符号名称与现有符号冲突

[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)

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

最佳答案

命名空间重整解决方案

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

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

这是来自 onnx-tensorrt 项目的示例:

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

关于c++ - Protocol Buffers 的静态链接导致与现有符号的冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51795326/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com