2013-03-09 74 views
1

如何纠正以下错误编译的C代码与Redis的,当我编译使用credis API C语言编写测试代码:在Linux上

gcc -g -Wall -lcredis test_redis.c -o redisOUT 

/tmp/ccetckOb.o: In function `main': 
/home/faris/Downloads/credis-0.2.3/test_redis.c:12: undefined reference to `credis_connect' 
/home/faris/Downloads/credis-0.2.3/test_redis.c:15: undefined reference to `credis_ping' 
/home/faris/Downloads/credis-0.2.3/test_redis.c:18: undefined reference to `credis_set' 
/home/faris/Downloads/credis-0.2.3/test_redis.c:21: undefined reference to `credis_get' 
/home/faris/Downloads/credis-0.2.3/test_redis.c:25: undefined reference to `credis_close' 

collect2: error: ld returned 1 exit status 

例如在:http://code.google.com/p/credis/wiki/Examples

我破坏我的头这么长。

感谢您的解决方案。

山姆Iverish

+0

你是否包括头文件? – teppic 2013-03-09 15:56:39

+0

是的,我已经包括credis.h – Sam 2013-03-09 15:57:30

回答

3

把图书馆以后引用它的源文件:

gcc -g -Wall test_redis.c -lcredis -o redisOUT 
+0

谢谢詹姆斯。我得到了另一个问题,redis服务器运行时使用默认设置。但是当我从C代码调用credis_connect(..)时,它返回NULL。任何想法? – Sam 2013-03-09 17:05:42

+0

对不起,我对Redis不太了解。你可能想要开一个新的问题。 – 2013-03-09 17:11:50

+0

为什么不使用hiredis官方的C客户端? https://github.com/redis/hiredis,从2年来看,信贷似乎没有得到维护 – r043v 2013-03-11 22:25:26