天天看点

2021-01-18

[libprotobuf ERROR google/protobuf/descriptor_database.cc:57] File already exists in database: udata.proto
[libprotobuf FATAL google/protobuf/descriptor.cc:954] CHECK failed: generated_database_->Add(encoded_file_descriptor, size):
Qt has caught an exception thrown from an event handler. Throwing
exceptions from an event handler is not supported in Qt.
You must not let any exception whatsoever propagate through Qt code.
If that is not possible, in Qt 5 you must at least reimplement
QCoreApplication::notify() and catch all exceptions there.
           

当在一个主程序中包含多个动态库,而所包含的动态库中都包含udata.proto生成的udata.pb.h,并使用了udata.pb.cc生成的udata.pb.o文件生成动态库时就会报上述protobuf的冲突。在网上搜了下大致解决办法有以下几钟:

  1. 把proto文件名称和命名空间(package)改掉。(这种方法亲测可行,但是代价较大)
  2. 把protobuf生成的所有主程序和动态库用到的pb.h、pb.cpp放到一个动态库里,然后A和B动态库都去包它。(我的测试环境不太一样,测试不可行)
  3. 把libprotobuf.so的链接方式改成静态链接,不使用.so的方式,使用.a的方式在A和B动态库链接。(这种方式要重编protobuf,如果项目较大不方便)
  4. 可以把udata.pb.cc文件中的InternalAddGeneratedFile和InternalRegisterGeneratedFile的return false改为return true。(一定要保证来自于同一个proto文件)
  5. 升级protobuf到3.4(未测试)

继续阅读