5

We are trying to implement a Protocol Buffers format (ONNX) importer for a C++ runtime. Our runtime will be used by frontend applications, which also use the Protocol Buffers models.

When trying to execute a process which runs both frontend and backend components, we are seeing errors indicating that a symbol name 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)

Is there any way to have two components (application and shared object) statically linked PB message handling code and register the same Protobuf symbols in one process? Is there a way to tell the other component not to re-register the PB messages?

Artur Wojcik
  • 51
  • 1
  • 2

2 Answers2

0

Namespace mangling solution

Protocol Buffers holds a global registry based on the .proto filename. When 2 pieces of software try to add the same PB message to this registry, you get a name conflict.

One way to work around this is to artificially change the PB Message namespace. You can define a different namespace for your PB message and rely on CMakefile to do the symbol replacement and renaming.

Here is an example from the onnx-tensorrt project:

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

postrational
  • 6,306
  • 3
  • 22
  • 27
0

Linking Protocol Buffers statically

Protocol Buffers holds a global registry based on the .proto filename. When 2 pieces of software try to add the same PB message to this registry, you get a name conflict.

One way to work around this is to link the entire Protocol Buffers library to your project statically. This effectively creates a separate registry in which PB messages can be registered.

Here is an example from the ngraph project:

https://github.com/NervanaSystems/ngraph/commit/3d664abd7b8cc8295b6da79689f9bf119d55a2dd

postrational
  • 6,306
  • 3
  • 22
  • 27