In fact, this is a pseudo-proposition. As long as Redis is properly compiled, the dynamic library file libhiredis.so is generated in the/deps/hiredis/directory.
In order to facilitate the learning of Redis source code, write some test procedures, and a single-step tracking debugging, you can create a new subdirectory/unit, write your own program below, such as:
/** ex01.c * * Created On:jan 9 * author:xxf*/#include<stdio.h>#include".. /src/sds.h"intMain () {SDS s= Sdsnew ("Hello"); size_t Len=Sdslen (s); printf ("string:%s\nlength:%d\n", S, Len); return 0;}
Then write a makefile:
. Phony:allall:ex01ex01:ex01.cgcc-o ex01-o1-g-ggdb ex01.c-l. /deps/hiredis/-lhiredis
To perform the compilation again:
$ make all
We can get the ex01 of our experimental procedure. The results of the operation are as follows:
~/workspace/redis-3.2.6/unit>/ex01 string:hellolength:5
The method is rather stupid, but it is enough for the time being.
Redis comes with unit tests that are organized with TCL feet and are not used now.
When debugging, the library code breakpoint should be hit in the file in the/deps/hireds/directory.
After the breakpoint, it is possible to show "optimized out" when the value of the local variable is viewed at the break point, which is optimized. The optimization level is then lowered. Open/deps/hiredis/makefile and find
Optimization?=-o3
Switch
Optimization?=-o1
Simple Rough!
Recompile the library libhiredis.so in the/deps/hiredis/directory, then go back to/unit/, recompile ex01, success, run EX01, error:
./ex01:error while loading shared libraries:libhiredis.so.0.11:cannot open Shared object File:no such file or director Y
The steps to resolve the problem are as follows:
1, in the/deps/hiredis/directory make install, the results are as follows:
Mkdir-p/usr/local/include/hiredis/usr/local/libcp-a hiredis.h async.h adapters/usr/local/include/hirediscp-a Libhiredis.so/usr/local/lib/libhiredis.so.0.11cd/usr/local/lib && LN-SF libhiredis.so.0.11 Libhiredis.so.0cd/usr/local/lib && ln-sf libhiredis.so.0 libhiredis.socp-a libhiredis.a/usr/local/lib
2. Modification /etc/ld.so.conf file, increase/usr/local/lib
3, the implementation of/sbin/ldconfig
Run ex01 again, success!
Single-step debugging, viewing variables, normal!
How do I compile a redis into a library for my own use?