麒麟系统中Qt Creator调用protobuf库时,版本冲突解决方法

场景描述

1.用protoc 3将编写的proto文件生成对应***.pb.h和***.pb.cc文件

2.在Qt Creator中通过导入外部库的方式导入protobuf的库(动态、静态都可以)

3.代码编译通过,运行时提示protobuf版本冲突

问题现象


12:39:32: Starting /mnt/hgfs/VMshare/TestCode/****/build-***-Desktop_Qt_5_14_1_GCC_64bit-Debug/*** ...
[libprotobuf FATAL google/protobuf/stubs/common.cc:87] This program was compiled against version 2.6.1 of the Protocol Buffer runtime library, which is not compatible with the installed version (3.11.4).  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-yHFhjH/mir-0.26.3+16.04.20170605/obj-x86_64-linux-gnu/src/protobuf/mir_protobuf.pb.cc".)
terminate called after throwing an instance of 'google::protobuf::FatalException'
  what():  This program was compiled against version 2.6.1 of the Protocol Buffer runtime library, which is not compatible with the installed version (3.11.4).  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-yHFhjH/mir-0.26.3+16.04.20170605/obj-x86_64-linux-gnu/src/protobuf/mir_protobuf.pb.cc".)
12:39:33: 程序异常结束。
12:39:33: The process was ended forcefully.
12:39:33: /mnt/hgfs/VMshare/TestCode/****/build-***-Desktop_Qt_5_14_1_GCC_64bit-Debug/*** crashed.

环境介绍

麒麟系统4.02(对应于ubuntu16.04)
qt 5.14.1 (系统自带qt4.8.7,可以通过qtchooser更默认版本)
protobuf 3.11.4
通过一个lib封装所有protobuf相关的操作,以及.proto文件转换生成的cxx文件。
一个app调用lib提供的功能。
错误出现在app启动阶段。

/************************/

最简单的解决办法:

用静态库替换动态库

replace

LIB += -lprotobuf

with

LIBS += /usr/local/lib/libprotobuf.a

参考:c++ - Conflict Protobuf versions - Stack Overflow

/***********************/

其他尝试的方法,仅供参考,上面换静态的方法应该就能解决问题了。

解决过程

1.卸载Ubuntu自带的protobuf;

  1. # sudo apt-get remove libprotobuf-dev
    # which protoc
    // 运行完“which protoc”会显示一个protoc的路径,如果没有显示则下面这条命令不必执行
    # rm /usr/local/bin/protoc
    // 具体路径以“which protoc”显示的为准
     
    到此,低版本的protobuf卸载完成。

2.安装特定版本的protobuf,在此以安装protobuf3.6.0为例;

前提:确保以下几个库都有安装

# sudo apt-get install autoconf automake libtool curl make g++ unzip

编译protobuf源码并安装;

(--prefix指定来安装目录到/usr/lib。然后进行编译和安装,缺省会安装/usr/local/lib,但是有些ubuntu系统默认不能ld这路径,需要去配置)

./autogen.sh
./configure --prefix=/usr
make
make check
sudo make install 
sudo ldconfig # refresh shared library cache.

3.重装QT Creator

进入qt的安装目录下卸载

一般ubuntu软件是安装在opt目录下,如果不在就需要找找了

进入安装目录下

sudo ./MaintenanceTool

Ubuntu下卸载Qt_Y_Hungry的博客-CSDN博客_ubuntu卸载qt

其他解决方法:

用管理员权限运行QtCreator,软件安装路径无影响,建议安装到/opt/目录下

方法1,默认安装QT至/home/***(用户)/ 目录下,运行QT Creator时,用管理员权限运行

sudo ./qtcreator

方法2,将QT安装在 /opt/ 目录下,安装过程中会提示输入管理员密码(变相的提升QT Creator的权限)

参考文档

1.qt版本的切换 

(1)通过qtchooser

Ubuntu16.04修改Linux系统默认Qt版本号,使用qtchooser工具方法,不修改配置文件_豫小牛的博客-CSDN博客_linux qtchooser

(2)修改配置文件

ubuntu16.04下qt4和qt5同时安装的切换_追求卓越583的博客-CSDN博客_ubuntu能同时安装qt4和qt5吗

2.protobuf版本冲突解决方法

Ubuntu16.04下安装QT5.9使用Protocol Buffer 不兼容问题报错解决办法_MajorChou的博客-CSDN博客_qt5gui_qgtk3themeplugin.cmake

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

文斗士

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值