天天看點

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(未測試)

繼續閱讀