QtCreator 配置 protobuf 环境
之前的开发一直是在 VS2017 + Qt5.14.2 的环境下,这次要转换成纯 QtCreator 的环境。在开始使用之初遇到了很多问题,今天,我就来把遇到的问题以及才过的坑总结给大家!
protobuf 的编译就不再说了,我是采用 cmake 编译的,选取的是 VS2017,既可以在 VS 环境中使用,也可以在 QtCreator 环境中使用。

上述图片是用 cmake 编译选择的编译环境,这里,我给大家贴出来了。
经过 cmake 编译后,使用 vs 工具可以生成 lib 库,就算 protobuf 编译完成啦!
那么,该如何应用到 QtCreator 中呢?
创建一个 QtCreator 程序,来到下面这个页面,重点来喽!

默认,程序会选择第一个 MSVC2015 的,因为在 VS 环境中使用的是 2017 的开发环境,此时,我们也选择对应的 MSVC2017 就可以了。
注意!!如果不涉及到跨平台时,不要使用 MinGW 环境,否则编译的 protobuf 是不可用的,会报出一些列错误,而且是跳到了 goole 的内部代码中,而且会让你一头雾水。一般情况下,在 windows 平台下开发,用 MSVC 就可以了。
直接安装 QtCrator 是没有 MSVC 环境的,此时就需要将 VS2017 安装上,并且还需要安装上两者之间的插件:qt-vsaddin-msvc2017-2.5.1.vsix
选择需要的开发环境后,直接一路 next,一直到项目创建完成。
接下来,就需要添加库啦!
添加外界库
鼠标右击项目,选择"Add Library..."

选择第二项,外界库

选择之后,出现下面的默认页面

Library File:导入库的 lib 文件夹
Library path:导入库的 include 文件夹
Paltform:默认我们就用 windows 环境,其余就可以删除了,其它的选择项采取默认值。
配置之后显示,如下

直接 next,就会自动配置到项目的*.pro 文件中

配置到这里就已经完成了,后续的使用与 VS 环境中的应用一致了。
我是中国好公民 st,一名 C++开发程序媛~
版权声明: 本文为 InfoQ 作者【中国好公民st】的原创文章。
原文链接:【http://xie.infoq.cn/article/bc733bf4378effe31aa9179cf】。文章转载请联系作者。
评论