c/assets/notes_01_c-basic_01_xdx_index.md.H45ZmOuP.js

286 lines
172 KiB
JavaScript
Raw Normal View History

import{_ as s,c as a,o as i,a6 as n}from"./chunks/framework.CZRoMP2i.js";const l="/c/assets/1.D60Zf6_d.png",e="/c/assets/2.D2-G6nV2.png",p="/c/assets/3.DpzkVk5V.png",t="/c/assets/4.BXk95GIP.png",r="/c/assets/5.CbWTB08W.png",c="/c/assets/6.twO9TCIg.png",h="/c/assets/7.CKOjeIvS.png",d="/c/assets/8.DKmR0CxE.png",o="/c/assets/9.Cudf77_s.gif",k="/c/assets/10.BBUUlhRC.png",u="/c/assets/11.iLABkB7O.png",g="/c/assets/12.BQuYWOU9.png",b="/c/assets/13.CslpH6j0.png",m="/c/assets/14.BAyvZdKq.png",E="/c/assets/15.C3oC1iUd.png",C="/c/assets/16.Ds-jsEZn.png",y="/c/assets/17.Cd37gMYs.png",F="/c/assets/18.CAw2z3gc.png",_="/c/assets/19.DdPThnr-.png",v="/c/assets/20.q_rvlDnY.png",B="/c/assets/21.JRHg9RZA.png",f="/c/assets/22.Baq-Hb06.png",A="/c/assets/23.c1ht53mu.png",D="/c/assets/24.CAZmH5Py.png",x="/c/assets/25.DWeCYBe9.png",q="/c/assets/26.2XM8pYni.png",w="/c/assets/27.CN0t-fuo.png",S="/c/assets/28.AcDh3LXQ.png",L="/c/assets/29.CUkDFAc6.png",z="/c/assets/30.picNTNaJ.png",P="/c/assets/31.DKX92RgJ.png",T="/c/assets/32.Bxr7QKI3.png",W="/c/assets/33.DuFWsOgW.png",M="/c/assets/34.Da9qUcfr.png",O="/c/assets/35.7_gEABSX.gif",U="/c/assets/36.C2KQYoVC.gif",R="/c/assets/37.RTUP8Vtx.png",N="/c/assets/38.Dq21DxwL.png",I="/c/assets/39.QmpUaNxU.png",V="/c/assets/40.DP0C29gZ.png",G="/c/assets/41.DwzHokd4.png",X="/c/assets/42.Bi6K26yA.png",$="/c/assets/43.Bw8DcEQ_.png",H="/c/assets/44.DPc8Z9rS.png",K="/c/assets/45.S84xHMTl.png",Q="/c/assets/46.iw3JQUkn.png",Y="/c/assets/47.ILeJt-HK.png",j="/c/assets/48.CHgm7khh.png",J="/c/assets/49.N1nqJaEg.png",Z="/c/assets/50.DHsnibMi.png",ss="/c/assets/51.BQr6Q0uV.png",as="/c/assets/52.BVemi2Lh.png",is="/c/assets/53.BHR69UXx.png",ns="/c/assets/54.CPSU5SJI.png",ls="/c/assets/55.CaQLoDlw.png",es="/c/assets/56.aRGy4XbL.png",ps="/c/assets/57.kNO9fmPR.png",ts="/c/assets/58.D4EkoC4o.png",rs="/c/assets/59.V23Lo9e_.png",cs="/c/assets/60.Du9LVeMB.png",hs="/c/assets/61.DdFg75U9.png",ds="/c/assets/62.C6bz6KtT.png",os="/c/assets/63.CB6LAhB5.png",ks="/c/assets/64.Bip8bkua.png",us="/c/assets/65.DRNHRduW.png",gs="/c/assets/66.Cth4qqEn.png",bs="/c/assets/67.DWGWZ64P.png",ms="/c/assets/68.3hDIDdvx.png",Es="/c/assets/69.Bw_dQ4ap.png",Cs="/c/assets/70.Cn_ubTyA.png",ys="/c/assets/71.C84EBqwB.png",Fs="/c/assets/72.dZfJY4eR.png",_s="/c/assets/73.B0zm0Z79.png",vs="/c/assets/74.CaTcEy1Q.png",Bs="/c/assets/75.iEc8mo9g.png",fs="/c/assets/76.Co2KxM6t.png",As="/c/assets/77.CaUm8Qhc.png",Ds="/c/assets/78.kOkqIKG6.png",xs="/c/assets/79.CyeASH-c.png",qs="/c/assets/80.CFdk60La.png",ws="/c/assets/81.Bhl-0uK_.png",Ss="/c/assets/82.Dni9KbXV.png",Ls="/c/assets/83.BXx10MCV.png",zs="/c/assets/84.CXcIKX1T.png",Ps="/c/assets/85.CQ3_QCQT.png",Ts="/c/assets/86.CQoDRJM5.gif",Ws="/c/assets/87.CPfwZvD9.gif",Ms="/c/assets/88.bxEomEjU.gif",Os="/c/assets/89.C_onhf2k.png",Us="/c/assets/90.Budj3s38.gif",Rs="/c/assets/91.CH8koQdu.gif",Ns="/c/assets/92.kUJhxMtg.png",Is="/c/assets/93.BJeJJW4_.png",Vs="/c/assets/94.BCuK6eJL.gif",Gs="/c/assets/95.rKC-z4z-.gif",Xs="/c/assets/96.BJE3xxuT.gif",$s="/c/assets/97.DJOq__O0.gif",Hs="/c/assets/98.BDt_0fRR.png",Ks="/c/assets/99.Bo5OawW8.png",Qs="/c/assets/100.sUWUfl5e.png",Ys="/c/assets/101.BK4jpnB8.png",js="/c/assets/102.EF8vdbSq.png",Js="/c/assets/103.DjxdA_Co.png",Zs="/c/assets/104.sp68q1hh.gif",sa="/c/assets/105.DhMRyxNN.gif",aa="/c/assets/106.CdcLZM0R.gif",ia="/c/assets/107.D-5AsTTr.png",na="/c/assets/108.2RQKmAUa.png",la="/c/assets/109.CI4xX8SM.png",ea="/c/assets/110.C8QUZ9v3.gif",pa="/c/assets/111.g5tQfhWz.gif",ta="/c/assets/112.CX0_1NsE.gif",ra="/c/assets/113.BrFJeoK6.png",ca="/c/assets/114.58TjSSjH.gif",ha="/c/assets/115.DmiFIqcy.svg",da="/c/assets/116.BasYWvkM.png",oa="/c/assets/117.CjFxJpBr.png",ka="/c/assets/118.Dm5Jspvp.gif",ua="/c/assets/119.1krCh8cy.gif",ga="/c/assets/120.DOSyahv7.gif",ba="/c/assets/121.BHEvX_FI.gif",ma="/c/assets/122.DFA0g1_d.gif",Ea="/c/assets/123.D50nO5eA.gif",Ca="/c/assets/124.cAvG1Qfq.png",ya="/c/assets/125.DpakQFWz.gif",Fa="/c/assets/126.Bg61j9QI.gif",_a="/c/assets/127.DPvD9UCw.gif",va="/c/assets/128.Ceu65U_n.gif",Ba="/c/assets/129.BWPFRK_8.gif",fa="/c/assets/130.Ct4TfxPf.gif",Aa="/c/assets/
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;s#https\\?://mirror.msys2.org/#https://mirrors.tuna.tsinghua.edu.cn/msys2/#g&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /etc/pacman.d/mirrorlist</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">*</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><img src="`+O+'" alt="" loading="lazy"></p><ul><li> gcc </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">pacman</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -Syu</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --noconfirm</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # </span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">pacman</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -Sy</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> base-devel</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --noconfirm</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # </span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">pacman</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -Sy</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> mingw-w64-ucrt-x86_64-toolchain</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --noconfirm</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # gcc </span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p> <code>pacman -Sy mingw-w64-x86_64-toolchain --noconfirm</code></p><ul><li> <code>mingw-w64-x86_64-toolchain</code> 使 MSVCRT MinGW C </li><li> <code>mingw-w64-ucrt-x86_64-toolchain</code> 使 Microsoft UCRT Windows </li></ul></div><p><img src="'+U+'" alt="" loading="lazy"></p><h4 id="_1-2-4-2--path-" tabindex="-1">1.2.4.2 path <a class="header-anchor" href="#_1-2-4-2--path-" aria-label="Permalink to &quot;1.2.4.2 path &quot;"></a></h4><ul><li> <code>1.2.2.2 path </code> </li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p> path <code>C:\\msys64\\ucrt64\\bin</code> </p></div><h2 id="_1-3--ide-" tabindex="-1">1.3 IDE <a class="header-anchor" href="#_1-3--ide-" aria-label="Permalink to &quot;1.3 IDE&quot;"></a></h2><ul><li><p
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Hello World&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p><img src="`+Ts+'" alt="" loading="lazy"></p><ul><li> <code>gcc</code> </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">gcc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.c</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.exe</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+Ws+'" alt="" loading="lazy"></p><ul><li> </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./HelloWorld.exe</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+Ms+'" alt="" loading="lazy"></p><h2 id="_2-2-vs-code-" tabindex="-1">2.2 VS Code <a class="header-anchor" href="#_2-2-vs-code-" aria-label="Permalink to &quot;2.2 VS Code &quot;"></a></h2><ul><li> <code></code></li></ul><p><img src="'+Os+'" alt="" loading="lazy"></p><ul><li> <code>vscode</code> </li></ul><p><img src="'+Us+'" alt="" loading="lazy"></p><ul><li> <code>vscode</code> <code>HelloWorld.c</code> </li></ul><p><img src="'+Rs+'" alt="" loading="lazy"></p><ul><li> VSCode C/C++ </li></ul><p><img src="'+Ns+'" alt="" loading="lazy"></p><p><img src="'+Is+`" alt="" loading="lazy"></p><ul><li> </li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Hello World&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p><img src="`+Vs+'" alt="" loading="lazy"></p><ul><li> <code>gcc</code> </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">gcc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.c</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -o</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> HelloWorld.exe</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+Gs+'" alt="" loading="lazy"></p><ul><li> </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">./HelloWorld.exe</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+Xs+'" alt="" loading="lazy"></p><ul><li> Code Runner </li></ul><p><img src="'+$s+'" alt="" loading="lazy"></p><h2 id="_2-3-vs-" tabindex="-1">2.3 VS <a class="header-anchor" href="#_2-3-vs-" aria-label="Permalink to &quot;2.3 VS &quot;"></a></h2><ul><li> </li></ul><p><img src="'+Hs+'" alt="" loading="lazy"></p><p><img src="'+Ks+'" alt="" loading="lazy"></p><p><img src="'+Qs+'" alt="" loading="lazy"></p><p><img src="'+Ys+'" alt="" loading="lazy"></p><ul><li> <code></code></li></ul><p><img src="'+js+'" alt="" loading="lazy"></p><p><img src="'+Js+'" alt="" loading="lazy"></p><ul><li> <code>HelloWorld.c</code> </li></ul><p><img src="'+Zs+`" alt="" loading="lazy"></p><ul><li> </li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Hello World&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p><img src="`+sa+'" alt="" loading="lazy"></p><ul><li> </li></ul><p><img src="'+aa+'" alt="" loading="lazy"></p><h2 id="_2-4-clion-" tabindex="-1">2.4 CLion <a class="header-anchor" href="#_2-4-clion-" aria-label="Permalink to &quot;2.4 CLion &quot;"></a></h2><ul><li> </li></ul><p><img src="'+ia+'" alt="" loading="lazy"></p><p><img src="'+na+'" alt="" loading="lazy"></p><p><img src="'+la+`" alt="" loading="lazy"></p><ul><li> </li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Hello World&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p><img src="`+ea+'" alt="" loading="lazy"></p><ul><li> </li></ul><p><img src="'+pa+'" alt="" loading="lazy"></p><ul><li> c main CLion </li></ul><p><img src="'+ta+'" alt="" loading="lazy"></p><ul><li> </li></ul><p><img src="'+ra+'" alt="" loading="lazy"></p><p><img src="'+ca+`" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p></p><div class="language-txt vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">txt</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>-Dfile.encoding=UTF-8</span></span>
<span class="line"><span>-Dconsole.encoding=UTF-8</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div></div><h1 id="--c--" tabindex="-1"> C <a class="header-anchor" href="#--c--" aria-label="Permalink to &quot; C &quot;"></a></h1><h2 id="_3-1-" tabindex="-1">3.1 <a class="header-anchor" href="#_3-1-" aria-label="Permalink to &quot;3.1 &quot;"></a></h2><ul><li> C C </li></ul><h2 id="_3-2-" tabindex="-1">3.2 <a class="header-anchor" href="#_3-2-" aria-label="Permalink to &quot;3.2 &quot;"></a></h2><ul><li> WindowsLinux MacOS </li><li> Windows 使 C/C++ <code>MSVC</code> Microsoft Visual C++ Visual Studio <ul><li> : Windows Windows API PE </li><li> : Visual Studio Debugger</li><li> : Windows </li><li> : Windows <s>MFCMicrosoft Foundation Class Library</s></li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>MSVC 使 Visual Studio Community 使 Visual Studio Community </p></div><ul><li> Linux 使 C/C++ <code>GCC</code> Linux GCC <ul><li> 广: Linux </li><li> : </li><li> : GDBGNU MakeAutoconf </li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>GCC WindowsLinux MacOS Windows GCC MinGWCygwin MSYS2</p><ul><li> MinGW GCC Windows Windows </li><li> Cygwin Windows Unix POSIX GCC </li><li> MSYS2 Windows Unix-like Windows Linux MSYS2 MinGW Cygwin </li></ul></div><ul><li> MacOS 使 C/C++ <code>Clang/LLVM</code> <ul><li> Xcode : Xcode Apple macOSiOStvOSwatchOS</li><li> : Apple GCC </li><li> : Clang C </li></ul></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p><
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // </span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // </span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 0</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h2 id="_4-3-" tabindex="-1">4.3 <a class="header-anchor" href="#_4-3-" aria-label="Permalink to &quot;4.3 &quot;"></a></h2><ul><li>C </li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">/*</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">  这是第一行注释</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">  这是第二行注释</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">  这是第三行注释</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">*/</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> 使</li><li> CLion <code>Ctrl + Alt + /</code> </li></ul></div><ul><li></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() { </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> /*</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> printf(1);</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> printf(2);</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> */</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">); </span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h1 id="-helloworld--" tabindex="-1">HelloWorld <a class="header-anchor" href="#-helloworld--" aria-label="Permalink to &quot;HelloWorld &quot;"></a></h1><h2 id="_5-1-" tabindex="-1">5.1 <a class="header-anchor" href="#_5-1-" aria-label="Permalink to &quot;5.1 &quot;"></a></h2><h3 id="_5-1-1-" tabindex="-1">5.1.1 <a class="header-anchor" href="#_5-1-1-" aria-label="Permalink to &quot;5.1.1 &quot;"></a></h3><ul><li> 使 <code>tab</code> 使 <code>shift + tab</code> </li><li> <code>2 + 4 = 6</code></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p> IDE CLion <code>Ctrl + Alt + L</code> </p></div><ul><li></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 2</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;c = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, c);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h3 id="_5-1-2-" tabindex="-1">5.1.2 <a class="header-anchor" href="#_5-1-2-" aria-label="Permalink to &quot;5.1.2 &quot;"></a></h3><ul><li> C <code></code><code></code></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p><code></code></p></div><ul><li></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){ </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b) {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">   return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><ul><li></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">()</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">{ </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&gt;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b) </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">   return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">; </span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h2 id="_5-2-" tabindex="-1">5.2 <a class="header-anchor" href="#_5-2-" aria-label="Permalink to &quot;5.2 &quot;"></a></h2><h3 id="_5-2-1-main-" tabindex="-1">5.2.1 main() <a class="header-anchor" href="#_5-2-1-main-" aria-label="Permalink to &quot;5.2.1 main() &quot;"></a></h3><ul><li> C main() main() </li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(){</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><ul><li> main() main() </li><li> main() <code>int</code> <code></code> main() main() </li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><ul><li> C <code>return 0</code> main() </li><li> main() <code>return 0</code> </li></ul></div><h3 id="_5-2-2-" tabindex="-1">5.2.2 <a class="header-anchor" href="#_5-2-2-" aria-label="Permalink to &quot;5.2.2 &quot;"></a></h3><ul><li> <code>{}</code> </li><li> C </li><li> <code>;</code></li><li> </li></ul><h3 id="_5-2-3-printf-" tabindex="-1">5.2.3 printf() <a class="header-anchor" href="#_5-2-3-printf-" aria-label="Permalink to &quot;5.2.3 printf() &quot;"></a></h3><ul><li>printf() </li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">const</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> char</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> *</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">__format</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, ...)</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><ul><li>printf() f format</li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Hello World&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // </span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><ul><li> <code>\\n</code></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span clas
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 编译器将在系统的标准头文件目录中查找文件。</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;filename&gt;</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// 编译器首先在当前目录中查找文件,如果未找到,再在标准头文件目录中查找。</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;filename&quot;</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h1 id="-clion--" tabindex="-1">CLion <a class="header-anchor" href="#-clion--" aria-label="Permalink to &quot;CLion &quot;"></a></h1><h2 id="_6-1--wsl2" tabindex="-1">6.1 WSL2 <a class="header-anchor" href="#_6-1--wsl2" aria-label="Permalink to &quot;6.1 WSL2&quot;"></a></h2><h3 id="_6-1-1-" tabindex="-1">6.1.1 <a class="header-anchor" href="#_6-1-1-" aria-label="Permalink to &quot;6.1.1 &quot;"></a></h3><ul><li>WSL2 Windows Subsystem for Linux 2 Windows Linux WSL2 WSL1 Linux WSL1 使广</li><li></li></ul><p><img src="`+ha+'" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>WSL2 </p><ul><li> <strong> Linux </strong>WSL2 使 Linux WSL2 Linux </li><li> <strong></strong>WSL2 WSL1 I/O WSL2 </li><li> <strong></strong>使 Linux WSL2 Linux WSL1 WSL2 </li><li> <strong></strong>WSL2 Windows </li><li> <strong>使</strong>WSL2 使</li></ul></div><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>WSL2 </p><ul><li> <strong></strong>WSL2 Linux Windows Linux </li><li> <strong></strong>使 WSL2 Windows Linux </li><li> <strong></strong>WSL2 Windows Linux </li><li> <strong> Linux </strong>WSL2 Windows Linux Docker</li></ul></div><h3 id="_6-1-2-wsl2-" tabindex="-1">6.1.2 WSL2 <a class="header-anchor" href="#_6-1-2-wsl2-" aria-label="Permalink to &quot;6.1.2 WSL2 &quot;"></a></h3><ul><li> BIOS UEFI </li></ul><p><img src="'+da+'" alt="" loading="lazy"></p><ul><li> </li></ul><p><img src="'+oa+'" alt="" loading="lazy"></p><ul><li> Linux Windows </li></ul><div class="language-powershell vp-adapt
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> groupinstall</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;Development Tools&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> gcc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> gcc-c++</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # GCC</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> cmake</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # cmake</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> make</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # make</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dnf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> gdb</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # gdb</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p><img src="`+Fa+'" alt="" loading="lazy"></p><ul><li> CLion </li></ul><p><img src="'+_a+`" alt="" loading="lazy"></p><h3 id="_6-1-4--wsl2" tabindex="-1">6.1.4 WSL2 <a class="header-anchor" href="#_6-1-4--wsl2" aria-label="Permalink to &quot;6.1.4 WSL2&quot;"></a></h3><ul><li> Ubuntu 24.04便 cmake </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> update</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> upgrade</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> build-essential</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> gcc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> g++</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # GCC </span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> cmake</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # cmake</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sudo</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> apt</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> gdb</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # gdb</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><img src="`+va+'" alt="" loading="lazy"></p><ul><li> CLion </li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p> GDB CLion </p></div><p><img src="'+Ba+'" alt="" loading="lazy"></p><h2 id="_6-2--clion--cmake-" tabindex="-1">6.2 CLion cmake <a class="header-anchor" href="#_6-2--clion--cmake-" aria-label="Permalink to &quot;6.2 CLion cmake &quot;"></a></h2><ul><li> CLoin cmake 便 cmake </li></ul><p><img src="'+fa+'" alt="" loading="lazy"></p><h2 id="_6-3--cmakelists-txt-" tabindex="-1">6.3 CMakeLists.txt <a class="header-anchor" href="#_6-3--cmakelists-txt-" aria-label="Permalink to &quot;6.3 CMakeLists.txt &quot;"></a></h2><ul><li> C main() <code>CMakeLists.txt</code> 便 C main() </li></ul><p><img src="'+Aa+`" alt="" loading="lazy"></p><ul><li><code>CMakeLists.txt</code> </li></ul><div class="language-txt vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">txt</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>cmake_minimum_required(VERSION 3.10)</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 项目名称和版本号</span></span>
<span class="line"><span>project(c-study VERSION 1.0 LANGUAGES C)</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 设置 C 标准</span></span>
<span class="line"><span>set(CMAKE_C_STANDARD 23)</span></span>
<span class="line"><span>set(CMAKE_C_STANDARD_REQUIRED True)</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 辅助函数用于递归查找所有源文件</span></span>
<span class="line"><span>function(collect_sources result dir)</span></span>
<span class="line"><span> file(GLOB_RECURSE new_sources &quot;\${dir}/*.c&quot;)</span></span>
<span class="line"><span> set(\${result} \${\${result}} \${new_sources} PARENT_SCOPE)</span></span>
<span class="line"><span>endfunction()</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 查找顶层 include 目录如果存在</span></span>
<span class="line"><span>if (EXISTS &quot;\${CMAKE_SOURCE_DIR}/include&quot;)</span></span>
<span class="line"><span> include_directories(\${CMAKE_SOURCE_DIR}/include)</span></span>
<span class="line"><span>endif ()</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 查找所有源文件</span></span>
<span class="line"><span>set(SOURCES)</span></span>
<span class="line"><span>collect_sources(SOURCES \${CMAKE_SOURCE_DIR})</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 用于存储已经处理过的可执行文件名防止重复</span></span>
<span class="line"><span>set(EXECUTABLE_NAMES)</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 创建可执行文件</span></span>
<span class="line"><span>foreach (SOURCE \${SOURCES})</span></span>
<span class="line"><span> # 获取文件的相对路径</span></span>
<span class="line"><span> file(RELATIVE_PATH REL_PATH \${CMAKE_SOURCE_DIR} \${SOURCE})</span></span>
<span class="line"><span> # 将路径中的斜杠替换为下划线生成唯一的可执行文件名</span></span>
<span class="line"><span> string(REPLACE &quot;/&quot; &quot;_&quot; EXECUTABLE_NAME \${REL_PATH})</span></span>
<span class="line"><span> string(REPLACE &quot;\\\\&quot; &quot;_&quot; EXECUTABLE_NAME \${EXECUTABLE_NAME})</span></span>
<span class="line"><span> string(REPLACE &quot;.&quot; &quot;_&quot; EXECUTABLE_NAME \${EXECUTABLE_NAME})</span></span>
<span class="line"><span></span></span>
<span class="line"><span> # 处理与 CMakeLists.txt 文件同名的问题</span></span>
<span class="line"><span> if (\${EXECUTABLE_NAME} STREQUAL &quot;CMakeLists_txt&quot;)</span></span>
<span class="line"><span> set(EXECUTABLE_NAME &quot;\${EXECUTABLE_NAME}_exec&quot;)</span></span>
<span class="line"><span> endif ()</span></span>
<span class="line"><span></span></span>
<span class="line"><span> # 检查是否已经创建过同名的可执行文件</span></span>
<span class="line"><span> if (NOT EXECUTABLE_NAME IN_LIST EXECUTABLE_NAMES)</span></span>
<span class="line"><span> list(APPEND EXECUTABLE_NAMES \${EXECUTABLE_NAME})</span></span>
<span class="line"><span></span></span>
<span class="line"><span> # 创建可执行文件</span></span>
<span class="line"><span> add_executable(\${EXECUTABLE_NAME} \${SOURCE})</span></span>
<span class="line"><span></span></span>
<span class="line"><span> # 查找源文件所在的目录并添加为包含目录头文件可能在同一目录下</span></span>
<span class="line"><span> get_filename_component(DIR \${SOURCE} DIRECTORY)</span></span>
<span class="line"><span> target_include_directories(\${EXECUTABLE_NAME} PRIVATE \${DIR})</span></span>
<span class="line"><span></span></span>
<span class="line"><span> # 检查并添加子目录中的 include 目录如果存在</span></span>
<span class="line"><span> if (EXISTS &quot;\${DIR}/include&quot;)</span></span>
<span class="line"><span> target_include_directories(\${EXECUTABLE_NAME} PRIVATE \${DIR}/include)</span></span>
<span class="line"><span> endif ()</span></span>
<span class="line"><span></span></span>
<span class="line"><span> # 检查并添加 module 目录中的所有 C 文件如果存在</span></span>
<span class="line"><span> if (EXISTS &quot;\${DIR}/module&quot;)</span></span>
<span class="line"><span> file(GLOB_RECURSE MODULE_SOURCES &quot;\${DIR}/module/*.c&quot;)</span></span>
<span class="line"><span> target_sources(\${EXECUTABLE_NAME} PRIVATE \${MODULE_SOURCES})</span></span>
<span class="line"><span> endif ()</span></span>
<span class="line"><span> endif ()</span></span>
<span class="line"><span>endforeach ()</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br><span class="line-number">59</span><br><span class="line-number">60</span><br><span class="line-number">61</span><br><span class="line-number">62</span><br><span class="line-number">63</span><br><span class="line-number">64</span><br></div></div><h2 id="_6-4--clang-format-" tabindex="-1">6.4 .clang-format <a class="header-anchor" href="#_6-4--clang-format-" aria-label="Permalink to &quot;6.4 .clang-format &quot;"></a></h2><ul><li> <code>.clang-format</code> 便 C </li></ul><p><img src="`+Da+`" alt="" loading="lazy"></p><ul><li><code>.clang-format</code> </li></ul><div class="language-txt vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">txt</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>BasedOnStyle: Google</span></span>
<span class="line"><span>IndentWidth: 4</span></span>
<span class="line"><span>UseTab: Never</span></span>
<span class="line"><span>ColumnLimit: 0</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 控制大括号的位置</span></span>
<span class="line"><span>BreakBeforeBraces: Attach</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 控制空行的使用</span></span>
<span class="line"><span>EmptyLineBeforeAccessModifier: Never</span></span>
<span class="line"><span>KeepEmptyLinesAtTheStartOfBlocks: true</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 控制短函数 if 语句和循环的格式</span></span>
<span class="line"><span>AllowShortFunctionsOnASingleLine: Empty</span></span>
<span class="line"><span>AllowShortIfStatementsOnASingleLine: false</span></span>
<span class="line"><span>AllowShortLoopsOnASingleLine: false</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 控制其他格式选项</span></span>
<span class="line"><span>AlignConsecutiveAssignments: true</span></span>
<span class="line"><span>AlignConsecutiveDeclarations: true</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 控制注释的格式化</span></span>
<span class="line"><span>ReflowComments: true</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 控制包含指令的格式化</span></span>
<span class="line"><span>IncludeBlocks: Regroup</span></span>
<span class="line"><span>SortIncludes: CaseInsensitive</span></span>
<span class="line"><span></span></span>
<span class="line"><span>SpaceBeforeParens: ControlStatements</span></span>
<span class="line"><span>SpacesInParentheses: false</span></span>
<span class="line"><span>SpacesInAngles: false</span></span>
<span class="line"><span>SpacesInContainerLiterals: false</span></span>
<span class="line"><span>SpacesInCStyleCastParentheses: false</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br></div></div><ul><li>CLion <code></code><code></code></li></ul><p><img src="`+xa+'" alt="" loading="lazy"></p><h2 id="_6-5--gitignore-" tabindex="-1">6.5 .gitignore <a class="header-anchor" href="#_6-5--gitignore-" aria-label="Permalink to &quot;6.5 .gitignore &quot;"></a></h2><ul><li> <code>.gitignore</code> 便 Git </li></ul><p><img src="'+qa+`" alt="" loading="lazy"></p><ul><li><code>.gitignore</code> </li></ul><div class="language-txt vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">txt</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>.vscode</span></span>
<span class="line"><span>.idea</span></span>
<span class="line"><span>cmake-build-*</span></span>
<span class="line"><span>build</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h2 id="_6-6-" tabindex="-1">6.6 <a class="header-anchor" href="#_6-6-" aria-label="Permalink to &quot;6.6 &quot;"></a></h2><ul><li></li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p><code> CMake </code></p></div><p><img src="`+wa+'" alt="" loading="lazy"></p><h1 id="-c--" tabindex="-1">C <a class="header-anchor" href="#-c--" aria-label="Permalink to &quot;C &quot;"></a></h1><h2 id="_7-1-" tabindex="-1">7.1 <a class="header-anchor" href="#_7-1-" aria-label="Permalink to &quot;7.1 &quot;"></a></h2><ul><li>C </li></ul><p><img src="'+Sa+'" alt="" loading="lazy"></p><ul><li> C </li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><p> <code>.c</code> </p></div><ul><li> C <code></code> <code>.obj</code> <code>.o</code> C </li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li><p> <code></code><code></code><code></code><code></code></p></li><li><p> <code></code><code>#include</code><code>#define</code></p><ul><li><p><code>#include &lt;stdio.h&gt;</code><code>stdio.h</code></p></li><li><p><code>#define PI 3.14</code><code>PI</code><code>3.14</code></p></li><li><p><code>#ifdef</code><code>#ifndef</code></p></li><li><p></p></li><li><p><code>.i</code></p></li></ul></li><li><p> <code></code><code>.s</code></p></li><li><p> <code></code><code>.o</code> <code>.obj</code></p></li></ul></div><ul><li> <code>*.obj</code> <code>*.o</code><code></code> <code>*.exe</code></li></ul><div class="important custom-block github-alert"><p class="custom-block-title">IMPORTANT</p><p></p><ul><li></li><li> C 使 C <EFBFBD>
<span class="line"><span>networkingMode=mirrored</span></span>
<span class="line"><span>dnsTunneling=true</span></span>
<span class="line"><span>firewall=true</span></span>
<span class="line"><span>autoProxy=true</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[experimental]</span></span>
<span class="line"><span># requires dnsTunneling but are also OPTIONAL</span></span>
<span class="line"><span>bestEffortDnsParsing=true</span></span>
<span class="line"><span>useWindowsDnsCache=true</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p><img src="`+Oa+'" alt="" loading="lazy"></p><ul><li></li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">wsl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --shutdown</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+Ua+'" alt="" loading="lazy"></p><ul><li></li></ul><p><img src="'+Ra+'" alt="" loading="lazy"></p><h2 id="_8-2-clion-" tabindex="-1">8.2 CLion <a class="header-anchor" href="#_8-2-clion-" aria-label="Permalink to &quot;8.2 CLion &quot;"></a></h2><ul><li> CLion run <code>printf</code> <code>scanf</code> </li></ul><p><img src="'+Na+'" alt="" loading="lazy"></p><ul><li> debug <code>printf</code> <code>scanf</code> </li></ul><p><img src="'+Ia+`" alt="" loading="lazy"></p><ul><li> <code>scanf</code> <code>scanf</code> <code></code></li></ul><div class="language-c vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;stdio.h&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> // 禁用 stdout 缓冲区</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> setbuf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(stdout, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">NULL</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a, b, c;</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot; a b c &quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">);</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> scanf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> %d</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> %d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">a, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">b, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&amp;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">c);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> int</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> result </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> a </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> b </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> c;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> printf</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> × </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> × </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> = </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">%d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, a, b, c, result);</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><ul><li></li></ul><p><img src="`+Va+'" alt="" loading="lazy"></p><h2 id="_8-3-" tabindex="-1">8.3 <a class="header-anchor" href="#_8-3-" aria-label="Permalink to &quot;8.3 &quot;"></a></h2><h3 id="_8-3-1-" tabindex="-1">8.3.1 <a class="header-anchor" href="#_8-3-1-" aria-label="Permalink to &quot;8.3.1 &quot;"></a></h3><ul><li>C 使C </li><li>使 <code>Valgrind</code> <code></code><code></code> <code>Valgrind</code> Linux </li></ul><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p>win 11 WSL2 Linux Linux VMware Workstation Linux </p></div><h3 id="_8-3-2-" tabindex="-1">8.3.2 <a class="header-anchor" href="#_8-3-2-" aria-label="Permalink to &quot;8.3.2 &quot;"></a></h3><ul><li> WSL2 Valgrind </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dnf</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> upgrade</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">dnf</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> valgrind</span><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"> # AlmaLinux</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">apt</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> update</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">apt</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> upgrade</span><span style="--shi
<span class="line"><span></span></span>
<span class="line"><span># 项目名称和版本号</span></span>
<span class="line"><span>project(c-study VERSION 1.0 LANGUAGES C)</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 设置 C 标准</span></span>
<span class="line"><span>set(CMAKE_C_STANDARD 23)</span></span>
<span class="line"><span>set(CMAKE_C_STANDARD_REQUIRED True)</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 辅助函数用于递归查找所有源文件</span></span>
<span class="line"><span>function(collect_sources result dir)</span></span>
<span class="line"><span> file(GLOB_RECURSE new_sources &quot;\${dir}/*.c&quot;)</span></span>
<span class="line"><span> set(\${result} \${\${result}} \${new_sources} PARENT_SCOPE)</span></span>
<span class="line"><span>endfunction()</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 查找顶层 include 目录如果存在</span></span>
<span class="line"><span>if (EXISTS &quot;\${CMAKE_SOURCE_DIR}/include&quot;)</span></span>
<span class="line"><span> include_directories(\${CMAKE_SOURCE_DIR}/include)</span></span>
<span class="line"><span>endif ()</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 查找所有源文件</span></span>
<span class="line"><span>set(SOURCES)</span></span>
<span class="line"><span>collect_sources(SOURCES \${CMAKE_SOURCE_DIR})</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 用于存储已经处理过的可执行文件名防止重复</span></span>
<span class="line"><span>set(EXECUTABLE_NAMES)</span></span>
<span class="line"><span></span></span>
<span class="line"><span># 创建可执行文件</span></span>
<span class="line"><span>foreach (SOURCE \${SOURCES})</span></span>
<span class="line"><span> # 获取文件的相对路径</span></span>
<span class="line"><span> file(RELATIVE_PATH REL_PATH \${CMAKE_SOURCE_DIR} \${SOURCE})</span></span>
<span class="line"><span> # 将路径中的斜杠替换为下划线生成唯一的可执行文件名</span></span>
<span class="line"><span> string(REPLACE &quot;/&quot; &quot;_&quot; EXECUTABLE_NAME \${REL_PATH})</span></span>
<span class="line"><span> string(REPLACE &quot;\\\\&quot; &quot;_&quot; EXECUTABLE_NAME \${EXECUTABLE_NAME})</span></span>
<span class="line"><span> string(REPLACE &quot;.&quot; &quot;_&quot; EXECUTABLE_NAME \${EXECUTABLE_NAME})</span></span>
<span class="line"><span></span></span>
<span class="line"><span> # 处理与 CMakeLists.txt 文件同名的问题</span></span>
<span class="line"><span> if (\${EXECUTABLE_NAME} STREQUAL &quot;CMakeLists_txt&quot;)</span></span>
<span class="line"><span> set(EXECUTABLE_NAME &quot;\${EXECUTABLE_NAME}_exec&quot;)</span></span>
<span class="line"><span> endif ()</span></span>
<span class="line"><span></span></span>
<span class="line"><span> # 检查是否已经创建过同名的可执行文件</span></span>
<span class="line"><span> if (NOT EXECUTABLE_NAME IN_LIST EXECUTABLE_NAMES)</span></span>
<span class="line"><span> list(APPEND EXECUTABLE_NAMES \${EXECUTABLE_NAME})</span></span>
<span class="line"><span></span></span>
<span class="line"><span> # 创建可执行文件</span></span>
<span class="line"><span> add_executable(\${EXECUTABLE_NAME} \${SOURCE})</span></span>
<span class="line"><span></span></span>
<span class="line"><span> # 查找源文件所在的目录并添加为包含目录头文件可能在同一目录下</span></span>
<span class="line"><span> get_filename_component(DIR \${SOURCE} DIRECTORY)</span></span>
<span class="line"><span> target_include_directories(\${EXECUTABLE_NAME} PRIVATE \${DIR})</span></span>
<span class="line"><span></span></span>
<span class="line"><span> # 检查并添加子目录中的 include 目录如果存在</span></span>
<span class="line"><span> if (EXISTS &quot;\${DIR}/include&quot;)</span></span>
<span class="line"><span> target_include_directories(\${EXECUTABLE_NAME} PRIVATE \${DIR}/include)</span></span>
<span class="line"><span> endif ()</span></span>
<span class="line"><span></span></span>
<span class="line"><span> # 检查并添加 module 目录中的所有 C 文件如果存在</span></span>
<span class="line"><span> if (EXISTS &quot;\${DIR}/module&quot;)</span></span>
<span class="line"><span> file(GLOB_RECURSE MODULE_SOURCES &quot;\${DIR}/module/*.c&quot;)</span></span>
<span class="line"><span> target_sources(\${EXECUTABLE_NAME} PRIVATE \${MODULE_SOURCES})</span></span>
<span class="line"><span> endif ()</span></span>
<span class="line"><span> endif ()</span></span>
<span class="line"><span>endforeach ()</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br><span class="line-number">59</span><br><span class="line-number">60</span><br><span class="line-number">61</span><br><span class="line-number">62</span><br><span class="line-number">63</span><br><span class="line-number">64</span><br></div></div><ul><li> CLion </li></ul><p><img src="`+Qa+'" alt="" loading="lazy"></p><ul><li> CLion valgrind </li></ul><p><img src="'+Ya+'" alt="" loading="lazy"></p><h2 id="_8-4-" tabindex="-1">8.4 <a class="header-anchor" href="#_8-4-" aria-label="Permalink to &quot;8.4 &quot;"></a></h2><h3 id="_8-4-1-" tabindex="-1">8.4.1 <a class="header-anchor" href="#_8-4-1-" aria-label="Permalink to &quot;8.4.1 &quot;"></a></h3><ul><li><code>perf</code> Linux </li></ul><h3 id="_8-4-2-" tabindex="-1">8.4.2 <a class="header-anchor" href="#_8-4-2-" aria-label="Permalink to &quot;8.4.2 &quot;"></a></h3><h4 id="_8-4-2-1-almalinux9" tabindex="-1">8.4.2.1 AlmaLinux9 <a class="header-anchor" href="#_8-4-2-1-almalinux9" aria-label="Permalink to &quot;8.4.2.1 AlmaLinux9&quot;"></a></h4><ul><li> WSL2 AlmaLinux perf </li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-li
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">apt</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> linux-tools-common</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> linux-tools-generic</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> linux-tools-</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">uname</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -r</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><img src="`+Ja+'" alt="" loading="lazy"></p><div class="note custom-block github-alert"><p class="custom-block-title">NOTE</p><p></p><p> WSL2 Ubuntu Ubuntu Canonical </p></div><ul><li></li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">uname</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -sr</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+Za+'" alt="" loading="lazy"></p><ul><li>便</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> KERNEL_VERSION</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">$(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">uname</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -r</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> |</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> cut</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -d</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;-&#39;</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -f1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+si+`" alt="" loading="lazy"></p><ul><li></li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">apt</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> update</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">\\</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> apt</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -y</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> binutils-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> debuginfod</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> default-jdk</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> default-jre</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libaio-dev</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libbabeltrace-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libcap-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libdw-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libdwarf-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libelf-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libiberty-dev</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> liblzma-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libnuma-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libperl-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libpfm4-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libslang2-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libssl-dev</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libtraceevent-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libunwind-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libzstd-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libzstd1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> python3-setuptools</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> python3</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> python3-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> systemtap-sdt-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> zlib1g-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bc</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> dwarves</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bison</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> flex</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libnewt-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libdwarf++0</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libelf++0</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libbfb0-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> python-dev-is-python3</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p><img src="`+ai+`" alt="" loading="lazy"></p><ul><li></li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">git</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> clone</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --depth</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 1</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --single-branch</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --branch=linux-msft-wsl-\${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">KERNEL_VERSION</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">}</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://github.com/microsoft/WSL2-Linux-Kernel.git</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><img src="`+ii+'" alt="" loading="lazy"></p><ul><li>编译内核代码:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> WSL2-Linux-Kernel</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -j</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> $(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">nproc</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">) </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">KCONFIG_CONFIG=Microsoft/config-wsl</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+ni+'" alt="" loading="lazy"></p><ul><li>编译 perf 工具:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> tools/perf</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> clean</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> &amp;&amp; </span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+li+'" alt="" loading="lazy"></p><ul><li>复制到 PATH 变量所指向的路径中:</li></ul><div class="language-shell vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cp</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> perf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /usr/bin/</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br></div></div><p><img src="'+ei+'" alt="" loading="lazy"></p><h3 id="_8-4-3-整合" tabindex="-1">8.4.3 整合 <a class="header-anchor" href="#_8-4-3-整合" aria-label="Permalink to &quot;8.4.3 整合&quot;"></a></h3><ul><li>CLion 中配置 perf 的路径:</li></ul><p><img src="'+pi+'" alt="" loading="lazy"></p><ul><li>在 CLion 中通过 perf 运行代码:</li></