使用hiredis(redis客户端库)
我已经安装了redis服务器,可以从命令行使用它。现在,我想用hiredis编写一个客户端程序。首先,我尝试编译hiredis目录中的example.c:使用hiredis(redis客户端库),redis,hiredis,Redis,Hiredis,我已经安装了redis服务器,可以从命令行使用它。现在,我想用hiredis编写一个客户端程序。首先,我尝试编译hiredis目录中的example.c: vishal@expmach:~/redis-2.6.14/deps/hiredis$ ls adapters async.h COPYING dict.h *example.c* example-libevent.c hiredis.c Makefile net.h s
vishal@expmach:~/redis-2.6.14/deps/hiredis$ ls
adapters async.h COPYING dict.h *example.c* example-libevent.c
hiredis.c Makefile net.h sds.c test.c async.c CHANGELOG.md dict.c example-
ae.c example-libev.c fmacros.h hiredis.h net.c README.md sds.h
以下是命令:
vishal@expmach:~/redis-2.6.14/deps/hiredis$ gcc -c -I hiredis example.c
vishal@expmach:~/redis-2.6.14/deps/hiredis$ gcc -o example -I hiredis -L hiredis -lhiredis -lm
/usr/bin/ld:找不到-lhiredis
collect2:ld返回了1个退出状态
我不知道如何着手解决这个问题。请帮助。为什么不直接使用提供的Makefile 制造 /雇佣的例子
为什么不直接使用提供的Makefile呢 制造 /雇佣的例子
谢谢我的计划是在一些现有代码中使用hiredis客户端库。所以我需要知道如何使用gcc编译它,我还在学习如何理解Makefiles。你能告诉我如何开始使用gcc吗?你需要先构建lib,然后是gcc-o hiredis example.o libhiredis.a。如果您键入make,您将看到为构建example而发出的所有命令。如果example.c和libhiredis.a位于同一目录中,则此命令有效。但是当我把example.c放在另一个目录中时,我会得到一个错误的提示:“gcc:libhiredis.a:没有这样的文件或目录”,只要看看任何一个gcc教程,你就会很快得到它。祝你好运谢谢我的计划是在一些现有代码中使用hiredis客户端库。所以我需要知道如何使用gcc编译它,我还在学习如何理解Makefiles。你能告诉我如何开始使用gcc吗?你需要先构建lib,然后是gcc-o hiredis example.o libhiredis.a。如果您键入make,您将看到为构建example而发出的所有命令。如果example.c和libhiredis.a位于同一目录中,则此命令有效。但是当我把example.c放在另一个目录中时,我会得到一个错误的提示:“gcc:libhiredis.a:没有这样的文件或目录”,只要看看任何一个gcc教程,你就会很快得到它。祝你好运试试这个:
sudo-echo”/usr/local/lib>sudo/etc/ld.so.conf.d/local.conf
&sudo-ldconfig
。然后像这样编译example.c:gcc example.c-o example-l hiredis-I/usr/local/include/hiredis/
试试这个:sudo-echo/usr/local/lib>sudo/etc/ld.so.conf.d/local.conf
&sudo-ldconfig
。然后像这样编译example.c:gcc example.c-o example-l hiredis-I/usr/local/include/hiredis/
gcc -o example example.c -lhiredis $(pkg-config --cflags --libs glib-2.0)