几个共享对象使用相同的 proto 导致错误:文件已存在于数据库中 [英] Several shared object using same proto leading the the error: file already exists in database

查看:177
本文介绍了几个共享对象使用相同的 proto 导致错误:文件已存在于数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与 protobuf3 相关的错误

An error related to protobuf3

我有一个项目,它有一个 C++ 可执行核心和几个称为插件的共享对象(.so、.dll).当核心启动时,它将使用 dlopen 加载这些插件.核心和插件使用 protobuf 作为通信协议,因此他们必须将生成的 .pb.cc.ph.h 文件编译成他们的二进制文件,以获得串行器/解串器.并且 libprotobuf.so 链接到核心和插件.当我启动核心时,它崩溃并显示错误:文件已存在于数据库中,#863

I have a project that have an c++ executable core, and several shared objects (.so, .dll) called plugins. When the core launches, it will load those plugins with dlopen. The core and plugins using protobuf as communication protocol, so they have to compile the generated .pb.cc and .ph.h files into their binaries to have the copy of the serializer/deserializer. And libprotobuf.so link to both the core and plugins. When I launch the core, it crushes with error: file already exists in database, same error in #863

我使用的是 protobuf-3 beta2 和 Ubuntu 14.04.此错误仅发生在 Linux 上.该程序在 Windows 和 OS X 上运行良好.

I'm using protobuf-3 beta2, and Ubuntu 14.04. This error only happens on Linux. The program works fine on Windows and OS X.

我还尝试了另一种方法,将所有生成的 protobuf 文件编译成动态库(protocol.so),然后将核心和插件链接到 protocol.solibprotobuf.so.这工作正常.当然,因为在 #1062 中该错误已被修复.但是当我把protocol.so 改成protocol.a 时,它又失败了.我认为它与单独编译生成的 .pb.cc 相同.

I have also tried another way which compile all the generated protobuf files into a dynamic library (protocol.so), then the core and plugins were linked to protocol.so and libprotobuf.so. This works fine. Of course, because in #1062 the bug has been fixed. But when I changed the protocol.so into protocol.a, it failed again. I think it is same as compile generated .pb.cc separately.

我不想编译一个protocol.so,因为当我添加越来越多的插件时,扩展通信协议对我来说很不方便.我认为将生成的 .pb.cc 编译成插件的二进制文件会更好(这在 Windows 和 OS X 上运行良好).

I don't want to compile a protocol.so, because it is inconvenient for me to extend the communication protocol when I add more and more plugins. I think compile the generated .pb.cc into the plugin's binary is better (this work well on windows and OS X).

感谢任何修复此错误的建议.

Any suggestions to fix this error are appreciated.

推荐答案

当您有多个编译的相同 .pb.cc 文件副本共享一个 libprotobuf 副本时会出现问题.so.有两种方法可以避免这种情况:

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. 您已经找到的方法:将 .pb.cc 文件分解到共享库中.
  2. 将单独的 libprotobuf 副本链接到每个插件中.您需要为此库使用静态链接,即使用 libprotobuf.a 而不是 libprotobuf.so.请注意,使用此选项,在插件和基本应用程序之间传递指向 protobuf 类的指针是不安全的,因为它们使用 protobuf 库的单独副本,这可能会导致崩溃.您必须将序列化消息作为字节 blob 传递.幸运的是,这就是 protobuf 的全部意义所在.
  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.

这篇关于几个共享对象使用相同的 proto 导致错误:文件已存在于数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆