windows下hiredis的编译
来源:互联网 发布:虚拟专用网络服务器 编辑:程序博客网 时间:2024/06/06 20:52
将msvc项目中C/C++->运行库->MTD改为MDD再编译,要不静态连接能用多少别的库。
转自windows下hiredis的编译
编译环境,64位windows7 ultimate,VS2013 Ultimate
1.获取redis windows版
MS Open Technologies 官方主页
GitHub上的MSOpenTech/redis项目地址
2.编译两个lib: hiredis.lib和Win32_Interop.lib
打开从GitHub上clone下来的文件夹,打开里面的msvs文件夹中的RedisServer.sln
从解决方案资源管理器窗口编译hiredis工程和Win32_Interop工程(调试的时候请在debug模式下编译这两个库),此时便会在Debug/Release文件夹下生成这两个工程编译的lib
3.在自己的工程中使用
(1)添加上一步编译的这两个lib到工程中
(2)复制GItHub redis项目文件夹中src/Win32_Interop下所有头文件
(3)以及deps/hiredis下所有头文件(其中fmacros.h用src文件夹下的fmacros.h文件替代)
(4)再复制src/Win32_Interop/win32fixes.c到自己的工程目录,包含到工程文件中
(5)调整各个文件include的路径
(6)示例代码
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <hiredis.h>#define NO_QFORKIMPL //这一行必须加才能正常使用#include <Win32_Interop\win32fixes.h>#pragma comment(lib,"hiredis.lib")#pragma comment(lib,"Win32_Interop.lib")int main(){unsigned int j;redisContext *c;redisReply *reply;struct timeval timeout = { 1, 500000 }; // 1.5 secondsc = redisConnectWithTimeout((char*)"127.0.0.1", 6379, timeout);if (c->err) {printf("Connection error: %s\n", c->errstr);exit(1);}/* PING server */reply = (redisReply *)redisCommand(c, "PING");printf("PING: %s\n", reply->str);freeReplyObject(reply);/* Set a key */reply = (redisReply *)redisCommand(c, "SET %s %s", "foo", "hello world");printf("SET: %s\n", reply->str);freeReplyObject(reply);/* Set a key using binary safe API */reply = (redisReply *)redisCommand(c, "SET %b %b", "bar", 3, "hello", 5);printf("SET (binary API): %s\n", reply->str);freeReplyObject(reply);/* Try a GET and two INCR */reply = (redisReply *)redisCommand(c, "GET foo");printf("GET foo: %s\n", reply->str);freeReplyObject(reply);reply = (redisReply *)redisCommand(c, "INCR counter");printf("INCR counter: %lld\n", reply->integer);freeReplyObject(reply);/* again ... */reply = (redisReply *)redisCommand(c, "INCR counter");printf("INCR counter: %lld\n", reply->integer);freeReplyObject(reply);/* Create a list of numbers, from 0 to 9 */reply = (redisReply *)redisCommand(c, "DEL mylist");freeReplyObject(reply);for (j = 0; j < 10; j++) {char buf[64];sprintf_s(buf, 64, "%d", j);reply = (redisReply *)redisCommand(c, "LPUSH mylist element-%s", buf);freeReplyObject(reply);}/* Let's check what we have inside the list */reply = (redisReply *)redisCommand(c, "LRANGE mylist 0 -1");if (reply->type == REDIS_REPLY_ARRAY) {for (j = 0; j < reply->elements; j++) {printf("%u) %s\n", j, reply->element[j]->str);getchar();}}freeReplyObject(reply);return 0;}
PS.可能会碰到的编译错误
1.必须定义入口点,请在win32fixes.h之前加上#define NO_QFORKIMPL
2.各种与其他库的使用冲突,请右击项目->属性->配置属性->C/C++->代码生成->运行库->改成多线程调试(/MTd)或多线程(/MT)
并且在右击项目->属性->配置属性->连接器->命令行中输入/NODEFAULTLIB:libcmt.lib
3.error C4996,各种unsafe报错啊,请右击项目->属性->配置属性->C/C++->预处理器->预处理器定义->添加“_CRT_SECURE_NO_WARNINGS”(不带引号)
- windows下hiredis的编译
- windows下hiredis的编译
- windows下hiredis的编译
- windows下redis 和 hiredis的编译与使用
- 【数据库开发】windows下hiredis的编译(主要是包括一些异步编程的错误)
- windows下hiredis配置
- windows下配置hiredis
- windows下hiredis使用
- windows下hiredis使用
- hiredis windows x64编译记录
- 编译hiredis遇到的问题
- hiredis的各种windows版本
- ubuntu环境下的hiredis调试问题
- hiredis示例代码example-ac.c的编译
- linux下的hiredis的安装和使用(一)
- linux下的hiredis的安装和使用(二)
- Windows 下的QT 编译
- Windows下lapack的编译
- cocos2dx Configuration类
- Demo1.从服务器获取信息 服务器端代码
- Android开发之查看应用包名package和入口activity名称的方法
- 深入JVM锁机制2-Lock
- Linux系统介绍及日常管理
- windows下hiredis的编译
- Oracle to_char格式化函数
- 黑马程序员_java基础笔记第八天
- Demo1.从服务器获取信息 客户端代码
- FPGA 数字均幅Fir
- windows注册表索引
- Android系统设置settings应用学习(一)--允许未知来源应用安装
- 黑马程序员_java基础笔记第九天
- [源码下载]Demo2.模拟简单登陆-效果图 基于networkcomms2.3.1