当前位置:网站首页>Clion debugging redis6 source code
Clion debugging redis6 source code
2022-07-28 07:37:00 【Turn X7】
background
clion Use cmake To manage compilation redis Source code , and redis The source code itself uses native make, So directly redis Source code import clion Can't run directly , Need configuration cmake.
Write c The general steps of the procedure are :
1). Write source code with editor , Such as .c file .
2). Compile the code with the compiler to generate the target file , Such as .o.
3). Use linker to connect object code to generate executable , Such as .exe.
But if there are too many source files , One by one compilation will be particularly troublesome , So people think , Why not design a batch like program , To batch compile source files , So there was make Tools , It's an automated compilation tool , You can use one command to fully compile . But you need to write a rule file ,make Batch compile according to it , This file is makefile, So write makefile File is also a necessary skill for a programmer .
For a big project , To write makefile It's really a complicated thing , So people think again , Why not design a tool , After reading all the source files , Automatic generation makefile Well , So it came out cmake Tools , It can output all kinds of makefile perhaps project file , To help programmers reduce the burden . But then it comes to writing cmakelist file , It is cmake Rules on which . So there's no shortcut in the world of programming , Still have to be down-to-earth .
So the process is as follows :

A program , stay linux Run under , You have to write a makefile, If you want to migrate to other platforms , This makefile It won't work , Need to write another .
therefore , For cross platform , There is cmake,cmake Is to let programmers write in a unified syntax cmake file , then cmake It will help us generate the corresponding platform makefile.
So we chose cygwin Come on window Lower simulation linux Environmental Science ,cygwin By default, there is cmake Compiler tools .
One 、 Installation configuration cygwin
1) Open the website :https://cygwin.com/install.html

2) In the picture above install link ( The figure below ), Choose according to your computer 32 A still 64 position

download https://cygwin.com/setup-x86_64.exe( This is a 64 Bit , If you download 32 Bit , The following configuration and 64 The bits are the same )

3) install
Double click

successively :【 next step 】->【install from Internet】 -> 【 Set the download and installation path 】-> 【direct connection】 -> Select the download source ( You can add a Netease mirror station :http://mirrors.163.com/cygwin/ [ Reference resources http://mirrors.163.com/.help/cygwin.html])
Next, select the module to be installed , Search separately wget、 gcc-core、gcc-g++、make、gdb、binutils, All of the above projects are in devel Under the folder .

【 next step 】

continue 【 next step 】

continue 【 next step 】

continue 【 next step 】

Add Netease image and continue 【 next step 】
Select the package to install in the figure below ( We need to install wget、 gcc-core、gcc-g++、make、gdb、binutils):

stay search Box to search for the above toolset , Here's the picture :

And install a apt-cyg( Equivalent to linux Under the yum,cygwin Under no yum command )
Why install apt-cyg?
Installed apt-cyg You can use Ubuntu The use of apt-get install/remove Uninstalled the software , Very convenient .
GitHub Download script :https://github.com/transcode-open/apt-cyg

Unzip what you just downloaded zip file :

Copy apt-cyg, Paste the cygwin Of the installation directory bin Under the table of contents :

open Cygwin

Enter the command :
## This command will be followed by
apt-cyg install dos2unix
Because I've installed , So here we skip , This command tests apt-cyg Successful operation .
4) Add environment variables to cmd perhaps powershell Can be used in Linux command



Please configure the above environment variables according to your actual installation address .
Two 、 install clion
CLion yes JetBrains A brand new C/C++ Cross platform integrated development environment . Used to using idea Of java For programmers clion To debug redis The source code should be more comfortable , Compared with vc Much more comfortable .
what ?? I do java Now let me debug c Code ??
forehead ... Who stipulated java Programmers cannot master C/C++ Of ? Besides, redis It is c Written , You have to study redis Source code , Can you not c Pick it up again ?
Don't talk nonsense , Walk up !
1)、 Download and install the Chinese cracked version clion
link :https://pan.baidu.com/s/1o0HEOdqhWYBsfqxKgOZWog
Extraction code :cp5t
2)、 Once installed , It needs to be in clion Middle configuration cygwin compiler
In turn, click :【 file 】->【 Set up 】

3)、 Open the configuration dialog , choice 【 structure , perform , Deploy 】->【Toolchains】-> Click on “+” Number , choice 【Cygwin】, Configure just installed Cygwin Environmental Science , below cmake And other tools will automatically detect .

notes : except Cygwin outside , You can also configure MinGW,VS etc. .
If you use MinGW Words , Install well MinGW Many files will be missing after , So this tutorial uses Cygwin.
After the configuration is completed, start downloading redis The source .
3、 ... and 、clion Import redis Source code
1)、 We from git Pull up the latest stable version 6.x edition .
It is suggested that the official warehouse https://github.com/antirez/redis Fork Out of their own warehouse .
Why Fork ? Now that we start reading 、 Debugging the source code , We might write some comments , They have their own warehouse , Free to submit .
This article uses Redis The version is the latest 6.0.5 .

2)、 open gitbush, perform :
git clone -b 6.0 https://github.com/antirez/redis.git

3)、redis6 Source code import clion in
【 file 】->【New CMake Project from Sources…】

Choose just clone Of redis Source code , Click on 【 determine 】, Here's the picture :

Four 、 modify CMakeLists.txt file
Because of the modification CMakeLists.txt There are many documents in quantity and content , Limited space , Get the latest CMakeLists.txt File related configuration , Please add code to dazzle the class java Architects qq1 Group acquisition :963060292
5、 ... and 、 compile & debugging redis6 Source code
1)、redis6 After the source code is loaded ,cmake Will automatically compile , After compilation , choice redis-server|debug Options , Click on 【 function 】 that will do .
And the flower , success !redis The version is the latest version 6.0.5 edition , As shown in the figure below :

6、 ... and 、 Be careful
1、 Before compiling , Need to be in Cygwin64 Terminal On the implementation mkreleasehdr.sh Script , Because the script format is win Format , So we need to execute dos2unix Command conversion , After the conversion, execute .
## Transformation format
dos2unix mkreleasehdr.sh## perform mkreleasehdr.sh
./mkreleasehdr.sh
2、 The following error will be reported when running to the last step :
error while loading shared libraries: cyghiredis.dll: cannot open shared object file: No such file or directory
Solution : Need to put E:\mypro\redis6\redis\cmake-build-debug\deps\hiredis\cyghiredis.dll copy to E:\mypro\redis6\redis\cmake-build-debug\ Under the table of contents .
3、 Available online redis3 perhaps 5 Version of CMakeLists.txt The relevant configuration of the file is as follows: redis6 Can't run in .
relevant CMakeLists.txt For the specific configuration of the file, please move to :redis-6.0.5: fork Source code to your own warehouse , Easy to read in 、 debugging redis Freely submit comments when source code
4、apt-cyg Documents need to be used vscode open , hold windows Next line break CRLF Change to linux Under the LF:
Otherwise , You should get such an error when you use it later :/usr/bin/apt-cyg: line 25: $‘\r‘: command not found”
notes : I am smart Under the guidance of brother, it was successfully built redis Source reading environment , The complete source code address is as follows :
边栏推荐
- Daily question - split equal sum subset
- It has been rectified seven times and took half a month. Painful EMC summary
- EMC之 “不整改好别回来了”
- Retryer of guava
- 牛客Mysql——SQL必知必会
- Log in to heroku and the solution of IP address mismatch appears
- [solution] visual full link log tracking - log tracking system
- Image segmentation method
- Cdn.jsdelivr.net is not available, what should I do
- [shaders realize negative anti color effect _shader effect Chapter 11]
猜你喜欢
随机推荐
CAS vs Database optimistic lock
DNA修饰贵金属纳米颗粒|DNA脱氧核糖核酸修饰金属钯Pd纳米颗粒PdNPS-DNA
ArcGIS JS自定义Accessor,并通过watchUtils相关方法watch属性
Cdn.jsdelivr.net is not available, what should I do
5G 商用第三年:无人驾驶的“上山”与“下海”
Essential performance optimization topics in the interview~
Eventbus of guava
Log in to heroku and the solution of IP address mismatch appears
Deeply analyze the implementation of singleton mode
EMC中的基石-电磁兼容滤波知识大全!
“核弹级” Log4j 漏洞仍普遍存在,并造成持续影响
cdn.jsdelivr.net不可用,该怎么办
DNA修饰金属铑Rh纳米颗粒RhNPS-DNA(DNA修饰贵金属纳米颗粒)
guava之限流RateLimiter
ArcGIS JS 地图内外网环境判断问题
Soft exam certificate can be used like this! Get a certificate = get a professional title?
细说共模干扰和差模干扰
【google】解决google浏览器不弹出账号密码保存框且无法保存登录信息问题
The net loss of users occurred again, and China Mobile, which lost face, launched ultra-low price packages to win users
Daily question - split equal sum subset









