当前位置:网站首页>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 :
边栏推荐
猜你喜欢

cdn.jsdelivr.net不可用,该怎么办

Deeply analyze the implementation of singleton mode

软考证书还能这样用!拿到证书=获得职称?

LeNet5、AlexNet、VGGNet、ResNet

DNA修饰金属锇Os纳米颗粒OsNPS-DNA|DNA修饰金属铱纳米颗粒IrNPS-DNA

ASP. Net core technology insider and project practice after reading

EMC中class A和class B哪个更严格?

Learn software testing in two weeks? I was shocked!

VCF file production

Learning to estimate 3D hand pose from single RGB image & amp notes
随机推荐
教程篇(7.0) 06. 零信任网络访问ZTNA * FortiClient EMS * Fortinet 网络安全专家 NSE 5
How to understand CMS collector to reduce GC pause time
Continous Gesture Recognition with hand-orented spatiotemporal feature
CAS vs 数据库乐观锁
What is the root cause of EMC's problems?
DNA-Ag2SQDs脱氧核糖核酸DNA修饰硫化银Ag2S量子点的合成方法
flowable工作流所有业务概念
DNA修饰贵金属纳米颗粒|DNA修饰纳米铜颗粒CuNPS-DNA|研究要点
EMC中的基石-电磁兼容滤波知识大全!
Industry standards and certification of common electronic products
JS secondary linkage Department
VCF file production
Safflower STL
软考证书还能这样用!拿到证书=获得职称?
And is two numbers of S - two questions per day
The underlying principles of RDB persistence and AOF persistence of redis
删除链表中的节点——每日一题
(daily question) - the longest substring without repeated characters
再次出现用户净流失,大失颜面的中国移动推出超低价套餐争取用户
Niuke MySQL - SQL must know and know