今天有个新的需求,要在qt上使用Redis,最开始是根据这篇文章进行的处理,后来报错了,这里简单记录一下
-
Redis相关下载
首先需要下载以下两个工具https://github.com/redis/hiredis https://github.com/microsoftarchive/redis
-
打开
https://github.com/microsoftarchive/redis
这个文件中的mvsc
文件夹,并利用VS进行编译,编译出可执行文件,在x64/Release
下。
此时可以测试下生成的server
和cli
是否正常。 -
编译
mkdir build cd build cmake .. -G "Visual Studio 15 2017 Win64" 打开sln文件,使用vs生成dll库
这里需要注意,我与上边的参考链接不一样,主要是因为我的程序报了
:-1: error: skipping incompatible
的错误,查阅后这篇文章发现编译出的hiredis.dll 是32位的(可使用dumpbin /HEADERS hiredis.dll
查看),而我的Qt程序使用的是64位的MinGW。然后从评论区中找到了解决方案。 -
pro
文件添加内容unix|win32: LIBS += -L$$PWD/path/to/hiredis/build/Release -lhiredis INCLUDEPATH += $$PWD/path/to/hiredis DEPENDPATH += $$PWD/path/to/hiredis
-
然后编译就能通过啦。