2024-07-11 10:07:44 +02:00
<!DOCTYPE html>
< html lang = "zh-CN" dir = "ltr" >
< head >
< meta charset = "utf-8" >
2024-08-09 08:48:23 +02:00
< title > 第一章:开发环境的安装和配置(⭐) | Hi, 终于等到你< / title >
2024-07-11 10:07:44 +02:00
< meta name = "description" content = "许大仙前端、Java、大数据、云原生" >
2024-08-09 04:52:37 +02:00
< meta name = "generator" content = "VitePress v1.3.2" >
< link rel = "preload stylesheet" href = "/c/assets/style.8enJ9bsK.css" as = "style" >
2024-07-11 10:07:44 +02:00
2024-08-12 04:14:14 +02:00
< script type = "module" src = "/c/assets/app.C-I7wcDV.js" > < / script >
2024-07-11 10:13:52 +02:00
< link rel = "preload" href = "/c/assets/inter-roman-latin.Di8DUHzh.woff2" as = "font" type = "font/woff2" crossorigin = "" >
2024-08-12 04:14:14 +02:00
< link rel = "modulepreload" href = "/c/assets/chunks/theme.BNIUxhWq.js" >
2024-08-09 04:52:37 +02:00
< link rel = "modulepreload" href = "/c/assets/chunks/framework.CZRoMP2i.js" >
2024-08-12 03:33:45 +02:00
< link rel = "modulepreload" href = "/c/assets/notes_01_c-basic_01_xdx_index.md.e0LUVTXC.lean.js" >
2024-07-11 10:49:23 +02:00
< link rel = "shortcut icon" href = "/c//logo.svg" >
2024-07-11 10:07:44 +02:00
< meta name = "viewport" content = "width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no,shrink-to-fit=no" >
< meta name = "keywords" content = "许大仙,许大仙的博客" >
< script id = "check-dark-mode" > ( ( ) => { const e = localStorage . getItem ( "vitepress-theme-appearance" ) || "auto" , a = window . matchMedia ( "(prefers-color-scheme: dark)" ) . matches ; ( ! e || e === "auto" ? a : e === "dark" ) && document . documentElement . classList . add ( "dark" ) } ) ( ) ; < / script >
< script id = "check-mac-os" > document . documentElement . classList . toggle ( "mac" , /Mac|iPhone|iPod|iPad/i . test ( navigator . platform ) ) ; < / script >
< / head >
< body >
2024-08-11 07:59:11 +02:00
< div id = "app" > < div class = "Layout" data-v-5d98c3a5 > <!-- [ --> <!-- ] --> <!-- [ --> < span tabindex = "-1" data-v-0f60ec36 > < / span > < a href = "#VPContent" class = "VPSkipLink visually-hidden" data-v-0f60ec36 > Skip to content < / a > <!-- ] --> <!-- --> < header class = "VPNav" data-v-5d98c3a5 data-v-ae24b3ad > < div class = "VPNavBar has-sidebar top" data-v-ae24b3ad data-v-6aa21345 > < div class = "wrapper" data-v-6aa21345 > < div class = "container" data-v-6aa21345 > < div class = "title" data-v-6aa21345 > < div class = "VPNavBarTitle has-sidebar" data-v-6aa21345 data-v-ab179fa1 > < a class = "title" href = "/c/" data-v-ab179fa1 > <!-- [ --> <!-- ] --> <!-- [ --> < img class = "VPImage logo" src = "/c/logo.svg" alt data-v-8426fc1a > <!-- ] --> < span data-v-ab179fa1 > 许大仙< / span > <!-- [ --> <!-- ] --> < / a > < / div > < / div > < div class = "content" data-v-6aa21345 > < div class = "content-body" data-v-6aa21345 > <!-- [ --> <!-- ] --> < div class = "VPNavBarSearch search" data-v-6aa21345 > <!-- [ --> <!-- --> < div id = "local-search" > < button type = "button" class = "DocSearch DocSearch-Button" aria-label = "Search" > < span class = "DocSearch-Button-Container" > < span class = "vp-icon DocSearch-Search-Icon" > < / span > < span class = "DocSearch-Button-Placeholder" > Search< / span > < / span > < span class = "DocSearch-Button-Keys" > < kbd class = "DocSearch-Button-Key" > < / kbd > < kbd class = "DocSearch-Button-Key" > K< / kbd > < / span > < / button > < / div > <!-- ] --> < / div > < nav aria-labelledby = "main-nav-aria-label" class = "VPNavBarMenu menu" data-v-6aa21345 data-v-dc692963 > < span id = "main-nav-aria-label" class = "visually-hidden" data-v-dc692963 > Main Navigation < / span > <!-- [ --> <!-- [ --> < a class = "VPLink link vp-external-link-icon VPNavBarMenuLink" href = "https://aexiar.github.io/" target = "_blank" rel = "noreferrer" tabindex = "0" data-v-dc692963 data-v-9c663999 > <!-- [ --> < span data-v-9c663999 > 首页< / span > <!-- ] --> < / a > <!-- ] --> <!-- [ --> < a class = "VPLink link vp-external-link-icon VPNavBarMenuLink" href = "https://aexiar.github.io/coa6/notes/" target = "_blank" rel = "noreferrer" tabindex = "0" data-v-dc692963 data-v-9c663999 > <!-- [ --> < span data-v-9c663999 > 计组6件套< / span > <!-- ] --> < / a > <!-- ] --> <!-- [ --> < div class = "VPFlyout VPNavBarMenuGroup" data-v-dc692963 data-v-b6c34ac9 > < button type = "button" class = "button" aria-haspopup = "true" aria-expanded = "false" data-v-b6c34ac9 > < span class = "text" data-v-b6c34ac9 > <!-- --> < span data-v-b6c34ac9 > 编程语言< / span > < span class = "vpi-chevron-down text-icon" data-v-b6c34ac9 > < / span > < / span > < / button > < div class = "menu" data-v-b6c34ac9 > < div class = "VPMenu" data-v-b6c34ac9 data-v-b98bc113 > < div class = "items" data-v-b98bc113 > <!-- [ --> <!-- [ --> < div class = "VPMenuLink" data-v-b98bc113 data-v-43f1e123 > < a class = "VPLink link" href = "/c/notes/" data-v-43f1e123 > <!-- [ --> c/c++<!-- ] --> < / a > < / div > <!-- ] --> <!-- [ --> < div class = "VPMenuLink" data-v-b98bc113 data-v-43f1e123 > < a class = "VPLink link vp-external-link-icon" href = "https://aexiar.github.io/web-design/notes/" target = "_blank" rel = "noreferrer" data-v-43f1e123 > <!-- [ --> 前端<!-- ] --> < / a > < / div > <!-- ] --> <!-- [ --> < div class = "VPMenuLink" data-v-b98bc113 data-v-43f1e123 > < a class = "VPLink link vp-external-link-icon" href = "https://aexiar.github.io/java/notes/" target = "_blank" rel = "noreferrer" data-v-43f1e123 > <!-- [ --> Java<!-- ] --> < / a > < / div > <!-- ] --> <!-- [ --> < div class = "VPMenuLink" data-v-b98bc113 data-v-43f1e123 > < a class = "VPLink link vp-external-link-icon" href = "https://aexiar.github.io/big-data/notes/" target = "_blank" rel = "noreferrer" data-v-43f1e123 > <!-- [ --> 大数据<!-- ] --> < / a > < / div > <!-- ] --> <!-- [ --> < div class = "VPMenuLink" data-v-b98bc113 data-v-43f1e123 > < a class = "VPLink link vp-external-link-icon" href = "https://aexiar.github.io/linux/notes/" target = "_blank" rel = "noreferrer" data-v-43f1e123 > <!-- [ --> 云原生<!-- ] --> < / a > < / div > <!-- ] --> <!-- [ --> < div class = "VPMenuLink" data-v-b98bc113 data-v-43f1e123 > < a class = "VPLink link vp-external-link-icon" href = "https://aexiar.github.io/go/notes/" target = "_blank" rel = "noreferrer" data-v-43f1e123 > <!-- [ --> Go<!-- ] --> < / a > < / div > <!-- ] --> <!-- [ --> < div class = "VPMenuLink" data-v-b98bc113 data-v-43f1e123 > < a class = "VPLink link vp-external-link-icon" href = "https://aexiar.github.io/python/notes/" target = "_blank" rel = "noreferrer" data-v-43f1e123 > <!-- [ --> Python<!-- ] - -
2024-08-11 07:41:10 +02:00
< span class = "line" > < span style = "--shiki-light:#032F62;--shiki-dark:#9ECBFF;" > " s#https\?://mirror.msys2.org/#https://mirrors.tuna.tsinghua.edu.cn/msys2/#g" < / span > < span style = "--shiki-light:#005CC5;--shiki-dark:#79B8FF;" > \< / span > < / span >
2024-08-12 03:33:45 +02:00
< 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 = "/c/assets/35.7_gEABSX.gif" alt = "" > < / 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-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 > < p > < img src = "/c/assets/36.C2KQYoVC.gif" alt = "" > < / 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 "1.2.4.2 配置 path 环境变量"" > < / a > < / h4 > < ul > < li > 和 < code > 1.2.2.2 配置 path 环境变量< / code > 步骤相同:略。< / li > < / ul > < h2 id = "_1-3-什么是-ide-集成开发环境" tabindex = "-1" > 1.3 什么是 IDE( 集成开发环境) ? < a class = "header-anchor" href = "#_1-3-什么是-ide-集成开发环境" aria-label = "Permalink to "1.3 什么是 IDE( 集成开发环境) ? "" > < / a > < / h2 > < ul > < li > < p > 在实际开发中,除了< code > 编译器< / code > 是必须安装的工具之外,我们往往还需要其他的辅助软件,如下所示:< / p > < ul > < li > 编辑器:用来编写代码,并且给代码着色,以方便阅读。< / li > < li > 代码提示器:输入部分代码,即可提示全部代码,加速代码的编写过程。< / li > < li > 调试器:观察程序的每一个运行步骤,发现程序的逻辑错误。< / li > < li > 项目管理工具:对程序涉及到的所有资源进行管理,包括:源文件、图片、视频、第三方库等。< / li > < li > 漂亮的界面:各种按钮、面板、菜单、窗口等控件整齐排布,操作更方便。< / li > < / ul > < / li > < li > < p > 这些工具通常被打包在一起,统一安装和发布,
2024-07-11 10:07:44 +02:00
< 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;" > " Hello World" < / 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 >
2024-08-09 11:10:03 +02:00
< 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 = "/c/assets/86.CQoDRJM5.gif" alt = "" > < / 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 = "/c/assets/87.CPfwZvD9.gif" alt = "" > < / 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 = "/c/assets/88.bxEomEjU.gif" alt = "" > < / 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 "2.2 VS Code 版"" > < / a > < / h2 > < ul > < li > ① 新建一个< code > 空< / code > 文件夹(目录),用于存放代码:< / li > < / ul > < p > < img src = "/c/assets/89.C_onhf2k.png" alt = "" > < / p > < ul > < li > ② 通过 < code > vscode< / code > 打开该目录:< / li > < / ul > < p > < img src = "/c/assets/90.Budj3s38.gif" alt = "" > < / p > < ul > < li > ③ 在 < code > vscode< / code > 中新建 < code > HelloWorld.c< / code > 文件:< / li > < / ul > < p > < img src = "/c/assets/91.CH8koQdu.gif" alt = "" > < / p > < ul > < li > ④ 设置 VSCode 中 C/C++ 的代码格式为行尾风格(可选):< / li > < / ul > < p > < img src = "/c/assets/92.kUJhxMtg.png" alt = "" > < / p > < p > < img src = "/c/assets/93.BJeJJW4_.png" alt = "" > < / 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;" > < stdio.h> < / span > < / span >
2024-07-11 10:07:44 +02:00
< 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;" > " Hello World" < / 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 >
2024-08-09 11:10:03 +02:00
< 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 = "/c/assets/94.BCuK6eJL.gif" alt = "" > < / 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 = "/c/assets/95.rKC-z4z-.gif" alt = "" > < / 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 = "/c/assets/96.BJE3xxuT.gif" alt = "" > < / p > < ul > < li > ⑧ 安装 Code Runner 插件(步骤略),实现右键直接编译执行(可选):< / li > < / ul > < p > < img src = "/c/assets/97.DJOq__O0.gif" alt = "" > < / p > < h2 id = "_2-3-vs-版" tabindex = "-1" > 2.3 VS 版 < a class = "header-anchor" href = "#_2-3-vs-版" aria-label = "Permalink to "2.3 VS 版"" > < / a > < / h2 > < ul > < li > ① 新建空项目:< / li > < / ul > < p > < img src = "/c/assets/98.BDt_0fRR.png" alt = "" > < / p > < p > < img src = "/c/assets/99.Bo5OawW8.png" alt = "" > < / p > < p > < img src = "/c/assets/100.sUWUfl5e.png" alt = "" > < / p > < p > < img src = "/c/assets/101.BK4jpnB8.png" alt = "" > < / p > < ul > < li > ② 打开< code > 解决方案资源管理器< / code > : < / li > < / ul > < p > < img src = "/c/assets/102.EF8vdbSq.png" alt = "" > < / p > < p > < img src = "/c/assets/103.DjxdA_Co.png" alt = "" > < / p > < ul > < li > ③ 新建 < code > HelloWorld.c< / code > 文件:< / li > < / ul > < p > < img src = "/c/assets/104.sp68q1hh.gif" alt = "" > < / 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;" > < stdio.h> < / span > < / span >
2024-07-11 10:07:44 +02:00
< 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;" > " Hello World" < / 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 >
2024-08-09 11:10:03 +02:00
< 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 = "/c/assets/105.DhMRyxNN.gif" alt = "" > < / p > < ul > < li > ⑤ 编译和执行:< / li > < / ul > < p > < img src = "/c/assets/106.CdcLZM0R.gif" alt = "" > < / p > < h2 id = "_2-4-clion-版" tabindex = "-1" > 2.4 CLion 版 < a class = "header-anchor" href = "#_2-4-clion-版" aria-label = "Permalink to "2.4 CLion 版"" > < / a > < / h2 > < ul > < li > ① 新建空项目:< / li > < / ul > < p > < img src = "/c/assets/107.D-5AsTTr.png" alt = "" > < / p > < p > < img src = "/c/assets/108.2RQKmAUa.png" alt = "" > < / p > < p > < img src = "/c/assets/109.CI4xX8SM.png" alt = "" > < / 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;" > < stdio.h> < / span > < / span >
2024-07-11 10:07:44 +02:00
< 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;" > " Hello World" < / 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 >
2024-08-09 11:10:03 +02:00
< 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 = "/c/assets/110.C8QUZ9v3.gif" alt = "" > < / p > < ul > < li > ③ 编译和运行:< / li > < / ul > < p > < img src = "/c/assets/111.g5tQfhWz.gif" alt = "" > < / p > < ul > < li > ④ 默认情况下,一个项目只能有一个 c 源文件包含 main 函数,但是 CLion 可以有多个,如下:< / li > < / ul > < p > < img src = "/c/assets/112.CX0_1NsE.gif" alt = "" > < / p > < ul > < li > ⑤ 如果之后,有中文乱码问题,那么请做如下步骤:< / li > < / ul > < p > < img src = "/c/assets/113.BrFJeoK6.png" alt = "" > < / p > < p > < img src = "/c/assets/114.58TjSSjH.gif" alt = "" > < / 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 >
2024-08-11 07:41:10 +02:00
< 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 "第三章:五花八门的 C 语言编译器(⭐)"" > < / a > < / h1 > < h2 id = "_3-1-概述" tabindex = "-1" > 3.1 概述 < a class = "header-anchor" href = "#_3-1-概述" aria-label = "Permalink to "3.1 概述"" > < / 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 "3.2 桌面操作系统"" > < / a > < / h2 > < ul > < li > 目前而言,主流的桌面操作系统就是 Windows、Linux 和 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 > MFC( Microsoft 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 > ③ 丰富的工具链: 和 GDB( GNU 调试器) 、Make、Autoconf 等工具无缝集成。< / li > < / ul > < / li > < / ul > < div class = "note custom-block github-alert" > < p class = "custom-block-title" > NOTE< / p > < p > < / p > < p > 目前而言, GCC 已经属于跨平台的项目了,支持 Windows、Linux 和 MacOS ,在 Windows 上 GCC 的移植项目, 如: MinGW、Cygwin 以及 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 的所有平台( macOS、iOS、tvOS、watchOS) 的开发。< / 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 > <
2024-07-11 10:07:44 +02:00
< 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;" > " 你好,世界!!!" < / 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 >
2024-08-09 11:10:03 +02:00
< 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 "4.3 多行注释"" > < / 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 >
2024-07-11 10:07:44 +02:00
< 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;" > < stdio.h> < / 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;" > " 你好,世界!!!" < / 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 >
2024-08-09 11:10:03 +02:00
< 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 "第五章: HelloWorld 的规范(⭐)"" > < / a > < / h1 > < h2 id = "_5-1-规范的代码风格" tabindex = "-1" > 5.1 规范的代码风格 < a class = "header-anchor" href = "#_5-1-规范的代码风格" aria-label = "Permalink to "5.1 规范的代码风格"" > < / a > < / h2 > < h3 id = "_5-1-1-正确的缩进和空白" tabindex = "-1" > 5.1.1 正确的缩进和空白 < a class = "header-anchor" href = "#_5-1-1-正确的缩进和空白" aria-label = "Permalink to "5.1.1 正确的缩进和空白"" > < / 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;" > < stdio.h> < / span > < / span >
2024-07-11 10:07:44 +02:00
< 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;" > " c = < / span > < span style = "--shiki-light:#005CC5;--shiki-dark:#79B8FF;" > %d< / span > < span style = "--shiki-light:#032F62;--shiki-dark:#9ECBFF;" > " < / 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 >
2024-08-09 11:10:03 +02:00
< 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 "5.1.2 代码风格"" > < / 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 >
2024-07-11 10:07:44 +02:00
< 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;" > > < / 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;" > > < / 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 >
2024-08-09 11:10:03 +02:00
< 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 "5.2 代码细节剖析"" > < / 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 "5.2.1 main() 函数"" > < / 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 >
2024-07-11 10:07:44 +02:00
< 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 >
2024-08-09 11:10:03 +02:00
< 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 "5.2.2 函数体"" > < / 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 "5.2.3 printf() 函数"" > < / 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;" > " Hello World" < / 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 class
2024-07-11 10:07:44 +02:00
< 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;" > < filename> < / 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 >
2024-08-09 11:10:03 +02:00
< span class = "line" > < span style = "--shiki-light:#D73A49;--shiki-dark:#F97583;" > #include< / span > < span style = "--shiki-light:#032F62;--shiki-dark:#9ECBFF;" > " filename" < / 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 "第六章: CLion 高级配置(⭐)"" > < / a > < / h1 > < h2 id = "_6-1-安装和配置-wsl2" tabindex = "-1" > 6.1 安装和配置 WSL2 < a class = "header-anchor" href = "#_6-1-安装和配置-wsl2" aria-label = "Permalink to "6.1 安装和配置 WSL2"" > < / a > < / h2 > < h3 id = "_6-1-1-概述" tabindex = "-1" > 6.1.1 概述 < a class = "header-anchor" href = "#_6-1-1-概述" aria-label = "Permalink to "6.1.1 概述"" > < / a > < / h3 > < ul > < li > WSL 2, 全称为 Windows Subsystem for Linux 2, 是微软提供的一种技术, 允许用户在 Windows 操作系统上运行 Linux 内核。WSL 2 是 WSL 的升级版,它引入了一个真正的 Linux 内核来代替 WSL 1 中使用的兼容层,从而提供更高的性能和更广泛的系统调用支持。< / li > < li > 其架构图,如下所示:< / li > < / ul > < p > < img src = "/c/assets/115.CgqNV2hL.png" alt = "" > < / p > < ul > < li > < p > WSL2 的功能,如下所示:< / p > < ul > < li > ① < strong > 真实的Linux内核< / strong > : WSL 2 使用了微软开发的轻量级虚拟机,它包含了一个完整的 Linux 内核。这意味着 WSL 2 能够运行更多的 Linux 应用程序,并且支持更多的系统调用。< / li > < li > ② < strong > 文件系统性能提升< / strong > : WSL 2 的文件系统性能比 WSL 1 有显著提升。对于 I/O 密集型的操作, 如: 编译代码或数据库操作, WSL 2 能够提供更快的速度。< / li > < li > ③ < strong > 兼容性增强< / strong > :由于使用了真实的 Linux 内核, WSL 2 对 Linux 应用程序的兼容性大幅提高。许多在 WSL 1上不能运行或需要调整的应用程序, 可以在 WSL 2上直接运行。< / li > < li > ④ < strong > 网络功能改进< / strong > : WSL 2 提供了更好的网络集成,能够更容易地与 Windows 上的其他网络资源进行交互。< / li > < li > ⑤ < strong > 资源使用优化< / strong > : WSL 2 使用轻量级虚拟机,比传统的虚拟机占用更少的资源,同时提供了类似的隔离和安全性。< / li > < / ul > < / li > < li > < p > WSL 的用途,如下所示:< / p > < ul > < li > ① < strong > 开发环境< / strong > : WSL 2 为开发者提供了一个原生的Linux开发环境, 而无需离开 Windows 。这对于需要在 Linux 上开发、测试或运行应用程序的开发者非常有帮助。< / li > < li > ② < strong > 学习和实验< / strong > :用户可以使用 WSL 2 在Windows上学习和实验 Linux 命令行工具和应用程序,而无需设置双重引导系统或安装虚拟机。< / li > < li > ③ < strong > 多平台开发< / strong > : 对于跨平台开发者来说, WSL 2 允许他们在一个操作系统上同时进行 Windows 和 Linux 平台的开发和测试,提高工作效率。< / li > < li > ④ < strong > 运行 Linux 工具和应用程序< / strong > : WSL 2 支持在 Windows 上直接运行各种 Linux 工具和应用程序, 如: Docker、数据库、编程语言环境等。< / li > < / ul > < / li > < / ul > < 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 "6.1.2 WSL2 的安装"" > < / a > < / h3 > < ul > < li > ① BIOS 或 UEFI 中,开启虚拟化:步骤略。< / li > < / ul > < p > < img src = "/c/assets/116.BasYWvkM.png" alt = "" > < / p > < ul > < li > ② 查看是否开启了虚拟化:< / li > < / ul > < p > < img src = "/c/assets/117.CjFxJpBr.png" alt = "" > < / p > < ul > < li > ③ 启用适用于 Linux 的 Windows 子系统:< / li > < / ul > < div class = "language-powershell vp-adaptive-theme line-numbers-mode" > < button title = "Copy Code" class = "copy" > < / button > < span class = "lang" > powershell< / span > < pre class = "shiki shiki-themes github-light github-d
2024-07-11 10:07:44 +02:00
< 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;" > " Development Tools" < / 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 >
2024-08-09 11:10:03 +02:00
< 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 = "/c/assets/126.Bg61j9QI.gif" alt = "" > < / p > < ul > < li > 可以通过 CLion 测试是否安装成功:< / li > < / ul > < p > < img src = "/c/assets/127.DPvD9UCw.gif" alt = "" > < / 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 "6.1.4 配置 WSL2"" > < / 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;" > & & < / 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 >
2024-07-11 10:07:44 +02:00
< 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 >
2024-08-09 11:10:03 +02:00
< 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 = "/c/assets/128.Ceu65U_n.gif" alt = "" > < / 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 = "/c/assets/129.BWPFRK_8.gif" alt = "" > < / 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 "6.2 切换 CLion 中的 cmake 的工具链"" > < / a > < / h2 > < ul > < li > 可以在 CLoin 中切换 cmake 的工具链,以便支持不同平台的 cmake ,即:< / li > < / ul > < p > < img src = "/c/assets/130.Ct4TfxPf.gif" alt = "" > < / 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 "6.3 修改 CMakeLists.txt 文件"" > < / a > < / h2 > < ul > < li > 前文也提到了,在一个 C 语言项目中,只能有一个 main() 函数;但是,我们可以修改 < code > CMakeLists.txt< / code > 文件的内容,以便其支持在一个 C 语言项目中,可以有多个包含 main() 函数的文件,如下所示:< / li > < / ul > < p > < img src = "/c/assets/131.zsKtx_jV.png" alt = "" > < / 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 >
2024-07-11 10:07:44 +02:00
< 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 >
2024-07-26 01:28:10 +02:00
< span class = "line" > < span > set(CMAKE_C_STANDARD 23)< / span > < / span >
2024-07-11 10:07:44 +02:00
< 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 " ${dir}/*.c" )< / 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 " ${CMAKE_SOURCE_DIR}/include" )< / 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 " /" " _" EXECUTABLE_NAME ${REL_PATH})< / span > < / span >
< span class = "line" > < span > string(REPLACE " \\" " _" EXECUTABLE_NAME ${EXECUTABLE_NAME})< / span > < / span >
< span class = "line" > < span > string(REPLACE " ." " _" 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 " CMakeLists_txt" )< / span > < / span >
< span class = "line" > < span > set(EXECUTABLE_NAME " ${EXECUTABLE_NAME}_exec" )< / 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 " ${DIR}/include" )< / span > < / span >
< span class = "line" > < span > target_include_directories(${EXECUTABLE_NAME} PRIVATE ${DIR}/include)< / span > < / span >
< span class = "line" > < span > endif ()< / span > < / span >
2024-07-26 01:28:10 +02:00
< span class = "line" > < span > < / span > < / span >
< span class = "line" > < span > # 检查并添加 module 目录中的所有 C 文件(如果存在)< / span > < / span >
< span class = "line" > < span > if (EXISTS " ${DIR}/module" )< / span > < / span >
< span class = "line" > < span > file(GLOB_RECURSE MODULE_SOURCES " ${DIR}/module/*.c" )< / span > < / span >
< span class = "line" > < span > target_sources(${EXECUTABLE_NAME} PRIVATE ${MODULE_SOURCES})< / span > < / span >
< span class = "line" > < span > endif ()< / span > < / span >
2024-07-11 10:07:44 +02:00
< span class = "line" > < span > endif ()< / span > < / span >
2024-08-09 11:10:03 +02:00
< 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 "6.4 配置 .clang-format 文件"" > < / a > < / h2 > < ul > < li > 配置 < code > .clang-format< / code > 格式化文件,以便写代码的时候,可以自动保存并格式化 C 程序代码,如下所示:< / li > < / ul > < p > < img src = "/c/assets/132.3oqDAW0w.png" alt = "" > < / 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 >
2024-07-11 10:07:44 +02:00
< 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 >
2024-08-09 11:10:03 +02:00
< 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 = "/c/assets/133.D9TSeAa9.gif" alt = "" > < / p > < h2 id = "_6-5-配置-gitignore-文件" tabindex = "-1" > 6.5 配置 .gitignore 文件 < a class = "header-anchor" href = "#_6-5-配置-gitignore-文件" aria-label = "Permalink to "6.5 配置 .gitignore 文件"" > < / a > < / h2 > < ul > < li > 需要在项目中,配置 < code > .gitignore< / code > 文件,以便在提交代码到 Git 仓库的时候,忽略某些文件或目录,如下所示:< / li > < / ul > < p > < img src = "/c/assets/134.CCRgYIVq.png" alt = "" > < / 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 >
2024-07-11 10:07:44 +02:00
< span class = "line" > < span > .idea< / span > < / span >
< span class = "line" > < span > cmake-build-*< / span > < / span >
2024-08-11 07:41:10 +02:00
< 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 "6.6 演示"" > < / 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 = "/c/assets/135.C1t2T6FV.gif" alt = "" > < / p > < h1 id = "第七章-c-语言的编译过程-⭐" tabindex = "-1" > 第七章: C 语言的编译过程(⭐) < a class = "header-anchor" href = "#第七章-c-语言的编译过程-⭐" aria-label = "Permalink to "第七章: C 语言的编译过程(⭐)"" > < / a > < / h1 > < h2 id = "_7-1-概述" tabindex = "-1" > 7.1 概述 < a class = "header-anchor" href = "#_7-1-概述" aria-label = "Permalink to "7.1 概述"" > < / a > < / h2 > < ul > < li > C 程序的编译过程,如下所示:< / li > < / ul > < p > < img src = "/c/assets/136.Rqa4uHq6.png" alt = "" > < / 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 < stdio.h> < / 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
2024-07-26 01:17:43 +02:00
< 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 >
2024-08-09 11:10:03 +02:00
< 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 = "/c/assets/143.CKuuzuQ_.png" alt = "" > < / 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 = "/c/assets/144.B4r6Nv14.gif" alt = "" > < / p > < ul > < li > 此时,再打开终端,就没有这种提示了:< / li > < / ul > < p > < img src = "/c/assets/145.CvbhuZNK.png" alt = "" > < / p > < h2 id = "_8-2-clion-调试问题" tabindex = "-1" > 8.2 CLion 调试问题 < a class = "header-anchor" href = "#_8-2-clion-调试问题" aria-label = "Permalink to "8.2 CLion 调试问题"" > < / a > < / h2 > < ul > < li > 在 CLion 中进行 run( 运行) 程序的时候, 对于 < code > printf< / code > 函数或 < code > scanf< / code > 函数很正常,如下所示:< / li > < / ul > < p > < img src = "/c/assets/146.BPgYm4ZX.gif" alt = "" > < / p > < ul > < li > 但是,当我们 debug( 调试) 的时候,对于 < code > printf< / code > 函数或 < code > scanf< / code > 函数会一直没有输出,如下所示:< / li > < / ul > < p > < img src = "/c/assets/147.DH2fri13.gif" alt = "" > < / 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;" > < stdio.h> < / span > < / span >
2024-08-01 02:32:54 +02:00
< 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;" > " 请输入整数 a 、b 和 c 的值:" < / 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;" > " < / 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;" > " < / span > < span style = "--shiki-light:#24292E;--shiki-dark:#E1E4E8;" > , < / 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:#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;" > " < / 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;" > " < / 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 >
2024-08-09 11:10:03 +02:00
< 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 = "/c/assets/148.CDDIqy03.gif" alt = "" > < / p > < h2 id = "_8-3-内存泄露检测" tabindex = "-1" > 8.3 内存泄露检测 < a class = "header-anchor" href = "#_8-3-内存泄露检测" aria-label = "Permalink to "8.3 内存泄露检测"" > < / a > < / h2 > < h3 id = "_8-3-1-概述" tabindex = "-1" > 8.3.1 概述 < a class = "header-anchor" href = "#_8-3-1-概述" aria-label = "Permalink to "8.3.1 概述"" > < / 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 "8.3.2 安装"" > < / 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;" > & & < / 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;" > & & < / 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 = "
2024-08-01 07:49:31 +02:00
< 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 " ${dir}/*.c" )< / 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 " ${CMAKE_SOURCE_DIR}/include" )< / 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 " /" " _" EXECUTABLE_NAME ${REL_PATH})< / span > < / span >
< span class = "line" > < span > string(REPLACE " \\" " _" EXECUTABLE_NAME ${EXECUTABLE_NAME})< / span > < / span >
< span class = "line" > < span > string(REPLACE " ." " _" 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 " CMakeLists_txt" )< / span > < / span >
< span class = "line" > < span > set(EXECUTABLE_NAME " ${EXECUTABLE_NAME}_exec" )< / 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 " ${DIR}/include" )< / 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 " ${DIR}/module" )< / span > < / span >
< span class = "line" > < span > file(GLOB_RECURSE MODULE_SOURCES " ${DIR}/module/*.c" )< / 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 >
2024-08-09 11:10:03 +02:00
< 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 = "/c/assets/154.DdSfz-Pf.gif" alt = "" > < / p > < ul > < li > 在 CLion 中通过 valgrind 运行代码:< / li > < / ul > < p > < img src = "/c/assets/155.BMocjVt7.gif" alt = "" > < / p > < h2 id = "_8-4-性能分析" tabindex = "-1" > 8.4 性能分析 < a class = "header-anchor" href = "#_8-4-性能分析" aria-label = "Permalink to "8.4 性能分析"" > < / a > < / h2 > < h3 id = "_8-4-1-概述" tabindex = "-1" > 8.4.1 概述 < a class = "header-anchor" href = "#_8-4-1-概述" aria-label = "Permalink to "8.4.1 概述"" > < / 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 "8.4.2 安装"" > < / 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 "8.4.2.1 AlmaLinux9"" > < / 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 = "
< span class = "line" > < span style = "--shiki-light:#24292E;--shiki-dark:#E1E4E8;" > & & < / 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 = "/c/assets/157.ssadIF0D.gif" alt = "" > < / 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 = "/c/assets/158.Dq5lLq9v.gif" alt = "" > < / 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;" > ' -' < / 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 = "/c/assets/159.CJ0_loZ8.gif" alt = "" > < / 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;" > & & < / span > < span style = "--shiki-light:#005CC5;--shiki-dark:#79B8FF;" > \< / span > < / span >
2024-08-01 07:49:31 +02:00
< 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 >
2024-08-09 11:10:03 +02:00
< 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 = "/c/assets/160.BPOK9irZ.gif" alt = "" > < / 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 >
2024-08-01 07:49:31 +02:00
< 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 >
2024-08-12 03:33:45 +02:00
< 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 = "/c/assets/161.B1eB55rC.gif" alt = "" > < / 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 = "/c/assets/162.VIcU-hkN.gif" alt = "" > < / 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;" > & & < / 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 = "/c/assets/163.BM9viRZJ.gif" alt = "" > < / 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 = "/c/assets/164.DpMBA1SK.gif" alt = "" > < / p > < h3 id = "_8-4-3-整合" tabindex = "-1" > 8.4.3 整合 < a class = "header-anchor" href = "#_8-4-3-整合" aria-label = "Permalink to "8.4.3 整合"" > < / a > < / h3 > < ul > < li > CLion 中配置 perf 的路径:< / li > < / ul > < p > < img src = "/c/assets/165.DgXuU6LF.png" alt = "" > < / p > < ul > < li > 在 CLion 中通过 pe
2024-08-12 04:14:14 +02:00
< script > w i n d o w . _ _ V P _ H A S H _ M A P _ _ = J S O N . p a r s e ( " { \ " i n d e x . m d \ " : \ " n 0 W - F d - u \ " , \ " n o t e s _ 0 1 _ c - b a s i c _ 0 0 _ x d x _ i n d e x . m d \ " : \ " D S B f E d i 8 \ " , \ " n o t e s _ 0 1 _ c - b a s i c _ 0 1 _ x d x _ i n d e x . m d \ " : \ " e 0 L U V T X C \ " , \ " n o t e s _ 0 1 _ c - b a s i c _ 0 2 _ x d x _ i n d e x . m d \ " : \ " 0 G H s M M a 0 \ " , \ " n o t e s _ 0 1 _ c - b a s i c _ 0 3 _ x d x _ i n d e x . m d \ " : \ " C L v C g g 5 M \ " , \ " n o t e s _ 0 1 _ c - b a s i c _ 0 4 _ x d x _ i n d e x . m d \ " : \ " D k X f R s s o \ " , \ " n o t e s _ 0 1 _ c - b a s i c _ 0 5 _ x d x _ i n d e x . m d \ " : \ " C T O 1 N X P 8 \ " , \ " n o t e s _ 0 1 _ c - b a s i c _ 0 6 _ x d x _ i n d e x . m d \ " : \ " B 8 Z 5 K X t i \ " , \ " n o t e s _ 0 4 _ l i n u x _ 0 1 _ x d x _ i n d e x . m d \ " : \ " D 7 - U l H S H \ " , \ " n o t e s _ i n d e x . m d \ " : \ " b g N n s 6 d 1 \ " } " ) ; w i n d o w . _ _ V P _ S I T E _ D A T A _ _ = J S O N . p a r s e ( " { \ " l a n g \ " : \ " z h - C N \ " , \ " d i r \ " : \ " l t r \ " , \ " t i t l e \ " : \ " 许 大 仙 \ " , \ " t i t l e T e m p l a t e \ " : \ " H i , 终 于 等 到 你 \ " , \ " d e s c r i p t i o n \ " : \ " 许 大 仙 前 端 、 J a v a 、 大 数 据 、 云 原 生 \ " , \ " b a s e \ " : \ " / c / \ " , \ " h e a d \ " : [ ] , \ " r o u t e r \ " : { \ " p r e f e t c h L i n k s \ " : t r u e } , \ " a p p e a r a n c e \ " : t r u e , \ " t h e m e C o n f i g \ " : { \ " l a s t U p d a t e d T e x t \ " : \ " 上 次 更 新 \ " , \ " r e t u r n T o T o p L a b e l \ " : \ " 返 回 顶 部 \ " , \ " s e a r c h \ " : { \ " p r o v i d e r \ " : \ " l o c a l \ " } , \ " l o g o \ " : \ " / l o g o . s v g \ " , \ " n a v \ " : [ { \ " t e x t \ " : \ " 首 页 \ " , \ " l i n k \ " : \ " h t t p s : / / a e x i a r . g i t h u b . i o / \ " } , { \ " t e x t \ " : \ " 计 组 6 件 套 \ " , \ " l i n k \ " : \ " h t t p s : / / a e x i a r . g i t h u b . i o / c o a 6 / n o t e s / \ " } , { \ " t e x t \ " : \ " 编 程 语 言 \ " , \ " i t e m s \ " : [ { \ " t e x t \ " : \ " c / c + + \ " , \ " l i n k \ " : \ " / n o t e s / \ " } , { \ " t e x t \ " : \ " 前 端 \ " , \ " l i n k \ " : \ " h t t p s : / / a e x i a r . g i t h u b . i o / w e b - d e s i g n / n o t e s / \ " } , { \ " t e x t \ " : \ " J a v a \ " , \ " l i n k \ " : \ " h t t p s : / / a e x i a r . g i t h u b . i o / j a v a / n o t e s / \ " } , { \ " t e x t \ " : \ " 大 数 据 \ " , \ " l i n k \ " : \ " h t t p s : / / a e x i a r . g i t h u b . i o / b i g - d a t a / n o t e s / \ " } , { \ " t e x t \ " : \ " 云 原 生 \ " , \ " l i n k \ " : \ " h t t p s : / / a e x i a r . g i t h u b . i o / l i n u x / n o t e s / \ " } , { \ " t e x t \ " : \ " G o \ " , \ " l i n k \ " : \ " h t t p s : / / a e x i a r . g i t h u b . i o / g o / n o t e s / \ " } , { \ " t e x t \ " : \ " P y t h o n \ " , \ " l i n k \ " : \ " h t t p s : / / a e x i a r . g i t h u b . i o / p y t h o n / n o t e s / \ " } ] } , { \ " t e x t \ " : \ " 开 源 软 件 \ " , \ " l i n k \ " : \ " h t t p s : / / a e x i a r . g i t h u b . i o / o p e n - s o f t w a r e / n o t e s / \ " } ] , \ " s i d e b a r \ " : { \ " / n o t e s / \ " : [ { \ " t e x t \ " : \ " C 语 言 基 础 \ " , \ " c o l l a p s e d \ " : t r u e , \ " i t e m s \ " : [ { \ " t e x t \ " : \ " 编 程 基 础 \ " , \ " l i n k \ " : \ " / n o t e s / 0 1 _ c - b a s i c / 0 0 _ x d x / \ " } , { \ " t e x t \ " : \ " C 语 言 入 门 \ " , \ " l i n k \ " : \ " / n o t e s / 0 1 _ c - b a s i c / 0 1 _ x d x / \ " } , { \ " t e x t \ " : \ " 变 量 和 进 制 \ " , \ " l i n k \ " : \ " / n o t e s / 0 1 _ c - b a s i c / 0 2 _ x d x / \ " } , { \ " t e x t \ " : \ " 数 据 类 型 和 运 算 符 \ " , \ " l i n k \ " : \ " / n o t e s / 0 1 _ c - b a s i c / 0 3 _ x d x / \ " } , { \ " t e x t \ " : \ " 流 程 控 制 \ " , \ " l i n k \ " : \ " / n o t e s / 0 1 _ c - b a s i c / 0 4 _ x d x / \ " } , { \ " t e x t \ " : \ " 数 组 \ " , \ " l i n k \ " : \ " / n o t e s / 0 1 _ c - b a s i c / 0 5 _ x d x / \ " } , { \ " t e x t \ " : \ " 指 针 \ " , \ " l i n k \ " : \ " / n o t e s / 0 1 _ c - b a s i c / 0 6 _ x d x / \ " } , { \ " t e x t \ " : \ " 函 数 \ " , \ " l i n k \ " : \ " / n o t e s / 0 1 _ c - b a s i c / 0 7 _ x d x / \ " } , { \ " t e x t \ " : \ " 预 处 理 器 \ " , \ " l i n k \ " : \ " / n o t e s / 0 1 _ c - b a s i c / 0 8 _ x d x / \ " } , { \ " t e x t \ " : \ " 自 定 义 数 据 类 型 \ " , \ " l i n k \ " : \ " / n o t e s / 0 1 _ c - b a s i c / 0 9 _ x d x / \ " } , { \ " t e x t \ " : \ " 字 符 串 和 时 间 \ " , \ " l i n k \ " : \ " / n o t e s / 0 1 _ c - b a s i c / 1 0 _ x d x / \ " } , { \ " t e x t \ " : \ " 内 存 管 理 \ " , \ " l i n k \ " : \ " / n o t e s / 0 1 _ c - b a s i c / 1 1 _ x d x / \ " } , { \ " t e x t \ " : \ " 文 件 操 作 \ " , \ " l i n k \ " : \ " / n o t e s / 0 1 _ c - b a s i c / 1 2 _ x d x / \ " } , { \ " t e x t \ " : \ " 调 试 工 具 和 调 试 技 巧 ( g d b 和 m a k e ) \ " , \ " l i n k \ " : \ " / n o t e s / 0 1 _ c - b a s i c / 1 3 _ x d x / \ " } , { \ " t e x t \ " : \ " 常 用 库 函 数 \ " , \ " l i n k \ " : \ " / n o t e s / 0 1 _ c - b a s i c / 1 4 _ x d x / \ " } ] } , { \ " t e x t \ " : \ " C 语 言 高 级 \ " , \ " c o l l a p s e d \ " : t r u e , \ " i t e m s \ " : [ { \ " t e x t \ " : \ " 变 量 和 内 存 分 布 \ " , \ " l i n k \ " : \ " / n o t e s / 0 2 _ c - a d v a n c e / 0 1 _ x d x / \ " } , { \ " t e x t \ " : \ " 指 针 强 化 \ " , \ " l i n k \ " : \ " / n o t e s / 0 2 _ c - a d v a n c e / 0 2 _ x d x / \ " } , { \ " t e x t \ " : \ " 结 构 体 和 文 件 的 高 级 用 法 \ " , \ " l i n k \ " : \ " / n o t e s / 0 2 _ c - a d v a n c e / 0 3 _ x d x / \ " } , { \ " t e x t \ " : \ " 链 表 和 回 调 函 数 \ " , \ " l i n k \ " : \ " / n o t e s / 0 2 _ c - a d v a n c e / 0 4 _ x d x / \ " } , { \ " t e x t \ " : \ " 编 译 过 程 和 面 向 接 口 \ " , \ " l i n k \ " : \ " / n o t e s / 0 2 _ c - a d v a n c e / 0 5 _ x d x / \ " } ] } , { \ " t e x t \ " : \ " 项 目 构 建 工 具 \ " , \ " c o l l a p s e d \ " : t r u e , \ " i t e m s \ " : [ { \ " t e x t \ " : \ " m e s o n \ " , \ " c o l l a p s e d \ " : t r u e , \ " i t e m s \ " : [ { \ " t e x t \ " : \ " G r a d l e 入 门 \ " , \ " l i n k \ " : \ " / n o t e s / 0 3 _ b u i l d / 0 1 _ x d x / \ " } ] } , { \ " t e x t \ " : \ " c m a k e \ " , \ " c o l l a p s e d \ " : t r u e , \ " i t e m s \ " : [ { \ " t e x t \ " : \ " G r a d l e 入 门 \ " , \ " l i n k \ " : \ " / n o t e s / 0 3 _ b u i l d / 0 1 _ x d x / \ " } ] } , { \ " t e x t \ " : \ " c o n a n \ " , \ " l i n k \ " : \ " / n o t e s / 0 3 _ b u i l d / 0 1 _ $ { c o m m o n D i r e c t o r y N a m e } / \ " } , { \ " t e x t \ " : \ " G r a d l e \ " , \ " c o l l a p s e d \ " : t r u e , \ " i t e m s \ " : [ { \ " t e x t \ " : \ " G r a d l e 入 门 \ " , \ " l i n k \ " : \ " / n o t e s / 0 3 _ b u i l d / 0 1 _ x d x / \ " } ] } ] } , { \ " t e x t \ " : \ " L i n u x \ " , \ " c o l l a p s e d \ " : t r u e , \ " i t e m s \ " : [ { \ " t e x t \ " : \ " L i n u x 初 识 和 安 装 \ " , \ " l i n k \ " : \ " / n o t e s / 0 4 _ l i n u x / 0 1 _ x d x / \ " } ] } , { \ " t e x t \ " : \ " C + + 核 心 编 程 \ " , \ " c o l l a p s e d \ " : t r u e , \ " i t e m s \ " : [ ] } , { \ " t e x t \ " : \ " C + + 标 准 库 \ " , \ " c o l l a p s e d \ " : t r u e , \ " i t e m s \ " : [ ] } , { \ " t e x t \ " : \ " Q T 桌 面 开 发 \ " , \ " c o l
2024-07-11 10:07:44 +02:00
< / body >
< / html >