Several shared object using same proto leading the the error: file already exists in database

南笙酒味 提交于 2019-12-04 15:58:42

The problem happens when you have multiple compiled copies of the same .pb.cc file sharing a single copy of libprotobuf.so. There are two ways to avoid this:

  1. The way you already found: factor out the .pb.cc files into a shared library.
  2. Link a separate copy of libprotobuf into each plugin. You'll need to use static linking for this library, i.e. use libprotobuf.a rather than libprotobuf.so. Note that with this option, it is unsafe to pass a pointer to a protobuf class between the plugins and the base application, because they are using separate copies of the protobuf library, which can lead to crashes. You will have to pass serialized messages as byte blobs instead. Luckily, that's the whole point of protobuf.

I was able to get around this problem by adding RTLD_GLOBAL to dlopen which takes existing known symbols into account.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!