Skip to content

Commit

Permalink
更新vscode_clang修改一些主题设置
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuzhiy05 committed Dec 10, 2024
1 parent 92690f7 commit 8e29842
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 19 deletions.
2 changes: 1 addition & 1 deletion docs/.vuepress/dist/404.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/.vuepress/dist/article/027o3g1x/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/.vuepress/dist/article/j3qgcpng/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/.vuepress/dist/article/jaovy4gg/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/.vuepress/dist/blog/archives/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/.vuepress/dist/blog/categories/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/.vuepress/dist/blog/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/.vuepress/dist/blog/tags/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/.vuepress/dist/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/.vuepress/dist/sitemap.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/sitemap.xsl"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"><url><loc>https://github.com/</loc><lastmod>2024-11-04T09:00:14.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/027o3g1x/</loc><lastmod>2024-11-03T13:53:48.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/j3qgcpng/</loc><lastmod>2024-11-03T13:53:48.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/d3sghq29/</loc><lastmod>2024-12-04T09:01:14.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/72dkdlbu/</loc><lastmod>2024-12-04T09:01:14.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/xst10xfz/</loc><lastmod>2024-12-02T15:54:51.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/vqkwmfa2/</loc><lastmod>2024-12-05T09:01:36.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/j3e883z1/</loc><lastmod>2024-12-02T15:54:51.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/wpu7x9jw/</loc><lastmod>2024-12-02T15:54:51.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/data_struct/map_str/</loc><lastmod>2024-12-02T15:54:51.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/data_struct/</loc><lastmod>2024-12-02T15:54:51.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/jaovy4gg/</loc><lastmod>2024-12-02T15:54:51.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/math/mathformula/</loc><lastmod>2024-12-02T08:48:44.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/math/</loc><lastmod>2024-12-02T08:48:44.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/math/math/7ge8cr0s/</loc><changefreq>daily</changefreq></url><url><loc>https://github.com/test1/chapter3-4/</loc><lastmod>2024-12-02T08:48:44.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/test1/exception/</loc><lastmod>2024-12-02T08:48:44.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/test1/</loc><lastmod>2024-12-02T08:48:44.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/blog/</loc><changefreq>daily</changefreq></url><url><loc>https://github.com/blog/tags/</loc><changefreq>daily</changefreq></url><url><loc>https://github.com/blog/archives/</loc><changefreq>daily</changefreq></url><url><loc>https://github.com/blog/categories/</loc><changefreq>daily</changefreq></url></urlset>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"><url><loc>https://github.com/</loc><lastmod>2024-11-04T09:00:14.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/j3qgcpng/</loc><lastmod>2024-11-03T13:53:48.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/d3sghq29/</loc><lastmod>2024-12-04T09:01:14.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/72dkdlbu/</loc><lastmod>2024-12-04T09:01:14.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/xst10xfz/</loc><lastmod>2024-12-02T15:54:51.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/027o3g1x/</loc><lastmod>2024-11-03T13:53:48.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/oy4qci0t/</loc><lastmod>2024-12-09T15:37:00.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/j3e883z1/</loc><lastmod>2024-12-09T15:37:00.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/pc9qmrqh/</loc><lastmod>2024-12-09T15:37:00.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/wpu7x9jw/</loc><lastmod>2024-12-02T15:54:51.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/vqkwmfa2/</loc><lastmod>2024-12-05T09:01:36.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/data_struct/map_str/</loc><lastmod>2024-12-02T15:54:51.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/data_struct/</loc><lastmod>2024-12-02T15:54:51.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/article/jaovy4gg/</loc><lastmod>2024-12-02T15:54:51.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/math/mathformula/</loc><lastmod>2024-12-02T08:48:44.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/math/</loc><lastmod>2024-12-02T08:48:44.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/math/math/7ge8cr0s/</loc><lastmod>2024-12-09T15:37:00.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/test1/chapter3-4/</loc><lastmod>2024-12-02T08:48:44.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/test1/exception/</loc><lastmod>2024-12-02T08:48:44.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/test1/</loc><lastmod>2024-12-02T08:48:44.000Z</lastmod><changefreq>daily</changefreq></url><url><loc>https://github.com/blog/</loc><changefreq>daily</changefreq></url><url><loc>https://github.com/blog/tags/</loc><changefreq>daily</changefreq></url><url><loc>https://github.com/blog/archives/</loc><changefreq>daily</changefreq></url><url><loc>https://github.com/blog/categories/</loc><changefreq>daily</changefreq></url></urlset>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions docs/.vuepress/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ export default plumeTheme({
shiki: {
twoslash: true,
lineNumbers: 10,
languages: ["cpp", "powershell", "bash", "cmd"],
languages: ['cpp','powershell', 'csharp','json','cmake'],
},
markdownEnhance: { demo: true, mermaid: true, },
markdownPower: { caniuse: true, jsfiddle: true,fileTree: true, // :::file-tree 文件树容器
markdownEnhance: { demo: true },
markdownPower: { caniuse: true, jsfiddle: true,
fileTree: {
icon: 'colored', // 'simple' | 'colored'
}, // :::file-tree 文件树容器
plot: true,
// !!plot!! 隐秘文本
icons: true,
Expand Down
153 changes: 150 additions & 3 deletions docs/tools/vscode_clang.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,155 @@ permalink: /article/j3e883z1/
[下载链接](https://github.com/trcrsired/llvm-releases)
2.将`/.../llvm/bin``/.../x86_64-windows-gnu/bin` 路径添加到用户`path`
3.安装clangd插件
4.测试一下
`clang++ -o hello.exe hello.cpp --target=x86_64-windows-msvc --sysroot=系统根路径 -fuse-ld=lld -D_DLL=1 -lmsvcrt -flto=thin -stdlib=libc++`
4.创建一个项目文件夹此处为helloproject,进入文件夹,右键打打开powershell
5.测试clang
`clang --version`
测试cmake
`cmake --version`
测试ninja
`ninja --version`

--sysroot=D:\\workfile\\compiler\\windows-msvc-sysroot
编写一个最简单hello.cpp文件保存

首先编写CmakeLists.txt和CmakePresets.json


```cmake
cmake_minimum_required(VERSION 3.5.0)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED true)
set(CMAKE_CXX_EXTENSIONS OFF)
project(hello)
add_executable(hello hello.cpp)
```

```json
{"version": 8,
"configurePresets": [
{
"name": "clang",
"hidden": false,
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_C_COMPILER": "D:\\workfile\\compiler\\clang\\llvm\\bin\\clang.exe",
"CMAKE_CXX_COMPILER": "D:\\workfile\\compiler\\clang\\llvm\\bin\\clang++.exe",
"CMAKE_CXX_FLAGS": "--target=x86_64-windows-gnu --sysroot=D:\\workfile\\compiler\\clang\\x86_64-windows-gnu -fuse-ld=lld -rtlib=compiler-rt -unwindlib=libunwind -lc++abi -lunwind -lntdll -Wno-unused-command-line-argument -fcolor-diagnostics -stdlib=libc++",
"CMAKE_C_FLAGS": "--target=x86_64-windows-gnu --sysroot=D:\\workfile\\compiler\\clang\\x86_64-windows-gnu -fuse-ld=lld -rtlib=compiler-rt -unwindlib=libunwind -lc++abi -lunwind -lntdll -Wno-unused-command-line-argument -fcolor-diagnostics "
}
}
]
}
```

在当前项目文件夹下打开powershell,或使用vscode的终端,依次输入一下命令

```powershell
cmake -Bbuild --preset clang .
ninja -C build hello
./hello
```

这就是完整的使用cmake和ninja的构建,并执行的过程。
准备工作做好后
首先开始配置vscode相关配置
1.taskjson
taskjson相当于任务配置文件,而一个task任务相当于执行一个个命令行命令。把一个个命令行命令抽象成任务。
也就是说用taskjson中的任务代替你执行上述的命令
相比每次开始新项目时重新写taskjson,vscode支持配置默认任务。这是写在C:\Users\<用户名>\AppData\Roaming\Code\User\profiles文件中的全局任务设置。

当然这里我们先选择配置任务而不是默认生成的任务,注意这个默认生成的任务是全局的.点击配置任务后,`命令面板`也就是出现的下拉框。如果之前没有配置本地任务,则会出现`使用模板创建taskjson文件`,点击后,选择`Other`后会在本地项目的文件夹下创建一个.vscode文件夹其中包含一个task.json文件。其中包含了vscode模板创建的任务一般为` echo Hello`

:::file-tree

- helloproject
- .vscode
- task.json
- build
- Cmakefile
- ...
- .ninja_deps
- .ninja_log
- build.ninja
- cmake_install.cmake
- CmakeCache.txt
- hello.exe
- CmakeLists.txt
- CmakePresets.json
- hello.cpp

:::
首先提供以下三个最基础的代替上述命令的任务
```json
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "cmake-build",
"command": "cmake",
"args": [
"-Bbuild",
"--preset",
"clang",
"."
],
"options": {
"cwd": "${workspaceFolder}/"
},
"group": {
"kind": "build",
"isDefault": true
},
"detail": "cmake构建",
"problemMatcher": []
},
{
"type": "shell",
"label": "ninja-make",
"command": "ninja ",
"args": [
"-v"
],
"options": {
"cwd": "${workspaceFolder}/build"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": false
},
"detail": "ninja编译"
},
{
"label": "执行",
"type": "shell",
"command": "./hello",
"options": {
"cwd": "${workspaceFolder}/"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "执行exe",
"dependsOrder": "sequence",
"dependsOn": [
"cmake-build",
"ninja-make"
]
}
]
```
保存task.json文件后点击vscode的任务栏的`终端`选项,点击运行任务。在出现的下拉框中点击`执行`
$env:path.split(";")

clang++ -o main.exe main.cpp --target=x86_64-windows-msvc --sysroot=D:\\workfile\\compiler\\windows-msvc-sysroot -fuse-ld=lld -D_DLL=1 -lmsvcrt -flto=thin
```powershell
Expand Down Expand Up @@ -71,3 +216,5 @@ ninja -t clean 清除构建文件
ninja <目标> 编译对应项目 有时你的引入的库依赖太多文件 此时只构建你的目标文件

ninja -v 详细模式构建所有目标


0 comments on commit 8e29842

Please sign in to comment.