FileOptions with dynamic libraries: Multiple extension registrations
What version of protobuf and what language are you using? Version: v3.6.1 Language: C++
What operating system (Linux, Windows, ...) and version? Linux: Ubuntu 18.04 (KDE Neon)
What runtime / compiler are you using (e.g., python version or gcc version) GCC: 7.5.0 gRPC: v1.16.1
What did you do? Steps to reproduce the behavior:
- Add custom option to
.proto - Compile
.protofiles to static lib - Link this library to executable (compiled with
-rdynamic) - Link this library to dynamic libraries
- Open dynamic libraries using
dlopen(withRTLD_GLOBAL) - Executable not loading and
libprobobufproducing an error
What did you expect to see Correctly running application which uses protobuf extensions
What did you see instead?
Application not working and libprotobuf throwing exception:
[libprotobuf FATAL …/protobuf/src/google/protobuf/extension_set.cc:93] Multiple extension registrations for type "google.protobuf.FileOptions", field number 50000.
terminate called after throwing an instance of 'google::protobuf::FatalException'
what(): Multiple extension registrations for type "google.protobuf.FileOptions", field number 50000.
Anything else we should know about your project / environment
There are no extensions with same field number (and no extensions with same name either).
It is not possible to link static library only with executable because symbols inside shared libraries can't be found.
There are usage of protobuf types inside executable so you can't link library to dynamic libs too.
Using shared library is not possible without significant changes to build process.
It sounds like this custom option is either getting linked in more than once place, or getting dynamically loaded multiple times. To fix the problem you will have to make sure the option is only registered once.
@acozzette
It sounds like this custom option is either getting linked in more than once place, or getting dynamically loaded multiple times.
It is exactly what I said:
2. Compile .proto files to static lib
3. Link this library to executable (compiled with -rdynamic)
4. Link this library to dynamic libraries
libprotobuf then then calls Register function for extensions every time it loads. And this causing errors.
Is there any workaround for this?
We use "MessageOptions" to check a type which should be de-serialized in several dynamic libraries in one app. And the same issue occurs. Please provide solution for this issue or any workaround.
Sorry for the long delay. Are you still seeing this error in newer versions of protobuf?
We encountered this issue previously in the Eclipse sim@openPASS Project. A short test with protobuf v21.4 didn't show the problem anymore.
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.
This issue is labeled inactive because the last activity was over 90 days ago.
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.
This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.