Linux + protobuf + QT 兼容性问题解决

本文解决了protobuf与Qt版本不一致导致的问题,包括protobuf内部锁冲突及编译时版本验证失败。介绍了在Linux环境下,通过调整protobuf编译参数并修改Qt cmake配置来解决此问题的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题现象

问题一:
protobuf.internal.lock()冲突

问题二:
[libprotobuf FATAL google/protobuf/stubs/common.cc:79] This program was compiled against version 2.6.1 of the Protocol Buffer runtime library, which is not compatible with the installed version (3.5.1). Contact the program author for an update. If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library. (Version verification failed in “/build/mir-O8_xaj/mir-0.26.3+16.04.20170605/obj-x86_64-linux-gnu/src/protobuf/mir_protobuf.pb.cc”.)

环境介绍

linux mint 18.2
qt 5.9.5
protobuf 3.5.2
通过一个lib封装所有protobuf相关的操作,以及.proto文件转换生成的cxx文件。
一个app调用lib提供的功能。
错误出现在app启动阶段。

注:同样的代码在windows下并不会出现问题。

解决过程

解决问题一:

重新编译protobuf,编译前设置其参数为:

./configure --prefix=/(...)/build  --disable-shared

解决问题二:

参考这篇文章:protobuf与qt的冲突
https://stackoverflow.com/questions/45703619/protobuf-version-conflicts-with-qt

另外,如果要用cmake+qt的方式构建项目,则还需要删除QT中相应的cmake模块文件:Qt5Gui_QGtk3ThemePlugin.cmake。
个人体会,cmake 对 QT的支持在3.9以后的版本才变得方便。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值