diff --git a/docs/.vuepress/dist/404.html b/docs/.vuepress/dist/404.html index 9a40e3e..201b5b3 100644 --- a/docs/.vuepress/dist/404.html +++ b/docs/.vuepress/dist/404.html @@ -1 +1 @@ -
Skip to content

404

页面未找到

但是,如果你不改变方向,并且一直寻找,最终可能会到达你要去的地方。
\ No newline at end of file +
Skip to content

404

页面未找到

但是,如果你不改变方向,并且一直寻找,最终可能会到达你要去的地方。
\ No newline at end of file diff --git a/docs/.vuepress/dist/article/027o3g1x/index.html b/docs/.vuepress/dist/article/027o3g1x/index.html index b7e8914..fe91efc 100644 --- a/docs/.vuepress/dist/article/027o3g1x/index.html +++ b/docs/.vuepress/dist/article/027o3g1x/index.html @@ -1,4 +1,4 @@ -程序结构和执行
Skip to content

程序结构和执行

838字约3分钟

2024-11-02

AT&T汇编

指令 源操作数 目的操作数 描述内存中的位置 intel QWORD PTR[rbx] AT&T (%rbx)

16位数据 字 WORD 32位数据 双字 DWORD 64位数据 四字 QWORD

x86-64 提供了16个通用寄存器
rax eax ax al 返回值
rbx 被调用者保存 rcx 第四个参数 rdx 第三个参数 rsi esi si sil 第二个参数 rdi 第一个参数
rbp 栈底指针 r8 r8d r8w r8b 第五个参数 r9 第六个参数 r10 被调用者保存 ... r15 被调用者保存

mov 指令 MOV S D S->D 传送 源操作数是一个立即数,存储寄存器或内存中 目的操作数是一个"地址",也就是这个位置。它可以是寄存器或是内存地址 目的操作数指定为立即数时需要 movabsq指令 如 movabsq $0x0011223344556677 ,%rax %rax =0x0011223344556677 指令需要指明移动寄存器的部分大小(b,w,l,q) movl以寄存器为目的寄存器时会把寄存器的高四位设置为0

较小的原值移动到较大的目的地址 MOVS 以0填充高位 MOVZ 以符号位填充高位

cltq S R 符号位扩展%eax -> %rax

exampl movabsq$0x0011223344556677 ,%rax %rax =0x0011223344556677 movb $0xAA ,%dl %dl=AA 将立即数移动到寄存器rdx最低八位也就是dl movb %dl,%al %rax=0x00112233445566AA 将寄存器rdx的低八位%dl中的值移动到%al寄存器中 movsbq %dl ,%rax %rax=FFFFFFFFFFFFFFAA 跟据原字节最高位设置扩展 movzbq %dl,%rax %rax=00000000000000AA 零扩展

示例

long exchange (long *xo,long y){
+程序结构和执行
Skip to content

程序结构和执行

838字约3分钟

2024-11-02

AT&T汇编

指令 源操作数 目的操作数 描述内存中的位置 intel QWORD PTR[rbx] AT&T (%rbx)

16位数据 字 WORD 32位数据 双字 DWORD 64位数据 四字 QWORD

x86-64 提供了16个通用寄存器
rax eax ax al 返回值
rbx 被调用者保存 rcx 第四个参数 rdx 第三个参数 rsi esi si sil 第二个参数 rdi 第一个参数
rbp 栈底指针 r8 r8d r8w r8b 第五个参数 r9 第六个参数 r10 被调用者保存 ... r15 被调用者保存

mov 指令 MOV S D S->D 传送 源操作数是一个立即数,存储寄存器或内存中 目的操作数是一个"地址",也就是这个位置。它可以是寄存器或是内存地址 目的操作数指定为立即数时需要 movabsq指令 如 movabsq $0x0011223344556677 ,%rax %rax =0x0011223344556677 指令需要指明移动寄存器的部分大小(b,w,l,q) movl以寄存器为目的寄存器时会把寄存器的高四位设置为0

较小的原值移动到较大的目的地址 MOVS 以0填充高位 MOVZ 以符号位填充高位

cltq S R 符号位扩展%eax -> %rax

exampl movabsq$0x0011223344556677 ,%rax %rax =0x0011223344556677 movb $0xAA ,%dl %dl=AA 将立即数移动到寄存器rdx最低八位也就是dl movb %dl,%al %rax=0x00112233445566AA 将寄存器rdx的低八位%dl中的值移动到%al寄存器中 movsbq %dl ,%rax %rax=FFFFFFFFFFFFFFAA 跟据原字节最高位设置扩展 movzbq %dl,%rax %rax=00000000000000AA 零扩展

示例

long exchange (long *xo,long y){
     long x=*xp;
     *xp=y;
     return x;
@@ -8,4 +8,4 @@
 3 movq %rsi,(%rdi)   作为对比这里不加括号,因为值就存储在%rsi寄存器中,取%rsi寄存器存储的值,移动到%rdi寄存器值所指向的内存中。
 4 ret

pushq S 栈指针减少8(指针大小) 将四字压入栈 因为栈是倒过来画的地址由高到低 等价于 subq $8 ,%rsp movq %rbq,(%rsp) popq D 栈指针加8 将四字弹出 等价于 movq (%rsp),%rax addq $8,%rsp

算数操作 leaq S, D D <-&S 把S的地址传送给D INC D D <-D+1 加1 DEC D D <-D-1 减1 NEG 取负 NOR 取补 ADD 加 SUB S,D D<-D+S 减 IMUL 乘
XOR 异或 OR 或 AND 与 SAL S,D D <-D<<k 左移 SHL 左移同上 SAR 算数右移 SHR 逻辑右移

leaq 指令 load effective address 是movq指令的变形,他将有效地址写入到目的操作数,是从内存读数据到寄存器 如 设 %rdx中值为x leaq 7(%rdx,%rdx,4),%rax 将%rax中的值设置为5x+7 例

long scale (long x,long y ,long z){
     long t=x+4*y+12*z
-}

3.9.1

#例题3.46

3.1

%rax 0x100
0x104 0xAB
$0x108 0x108
(%rax) 0xFF
4(%rax) 0x103
9(%rcx,%rdx) 0x10c
260(%rcx,%rdx) 0x108
0xFC(,%rcx,4) 0x101
(%rax,rdx,4) 0x118

3.5

函数原型为 void decode1(long *xp,long *yp,long *zp) xp in %rdi yp in %rsi ,zp in % rdx

long xp1=*xp; long yp1=*xp; long zp1=*zp; *yp=xp1; *zp=yp1; *xp=zp1;

3.6

\ No newline at end of file +}

3.9.1

#例题3.46

3.1

%rax 0x100
0x104 0xAB
$0x108 0x108
(%rax) 0xFF
4(%rax) 0x103
9(%rcx,%rdx) 0x10c
260(%rcx,%rdx) 0x108
0xFC(,%rcx,4) 0x101
(%rax,rdx,4) 0x118

3.5

函数原型为 void decode1(long *xp,long *yp,long *zp) xp in %rdi yp in %rsi ,zp in % rdx

long xp1=*xp; long yp1=*xp; long zp1=*zp; *yp=xp1; *zp=yp1; *xp=zp1;

3.6

\ No newline at end of file diff --git a/docs/.vuepress/dist/article/j3qgcpng/index.html b/docs/.vuepress/dist/article/j3qgcpng/index.html index 2527188..eb59de1 100644 --- a/docs/.vuepress/dist/article/j3qgcpng/index.html +++ b/docs/.vuepress/dist/article/j3qgcpng/index.html @@ -1,4 +1,4 @@ -c++编程语言第四版
Skip to content

c++编程语言第四版

3683字约12分钟

2024-11-02

c++之旅

导言

本文是The Cpp Programming Language 4th edition的学习记录

If you find this "lightning tour" confusing, skip to the more systematic presentation starting in Chapter 6

总的来说前五张只是速览,并不该纠结于细节问题

The Basics

首先一如其他编程或计算机书籍一样,一个从源码到可执行文件的流程图介绍。不过这里本老爹也借此重申了所谓c++的兼容性

When we talk about portability of C++ programs, we usually mean portability of source code; that is, the source code can be successfully compiled and run on a variety of systems

也就是说谈论兼容性说的是源码兼容,一份符合c++标准的源码应该可以保证在任何所支持平台和对应版本的编译器编译的。尽管这是常识,不过我还是写这里用作提醒。 然后本老爹引入一个名词实体

The ISO C++ standard defines two kinds of entities:
• Core language features, such as built-in types (e.g., char and int) and loops (e.g., for-statements and while-statements)
• Standard-library components, such as containers (e.g., vector and map) and I/O operations (e.g., << and getline())

不过这里和cppreference所述的实体有些出入。我不知为何*语句(statement)*也被划入实体的范畴。不过相比"对象"这个概念,实体确实很少有人去讨论或表述。就我的理解实体就是在c++程序中能被操作或识别的事物。他是真实存在的概念但不必通过占用内存,执行操作之类事件观测他的存在。

C++ is a statically typed language. That is, the type of every entity (e.g., object, value, name, and expression) must be known to the compiler at its point of use. The type of an object determines the set of operations applicable to it

我觉得这是很有用的一句话。因为接受这句话或许能帮助我解决初学c++时期的一些困惑。我个人认为它和我之后所认识到的严格别名优化或通过union进行类型转换所造成的UB相关。

Every C++ program must have exactly one global function named main(). The program starts by executing that function. The int value returned by main(), if any, is the program’s return value to "the system." If no value is returned, the system will receive a value indicating successful completion.

这段话或许能从所有c++相关书籍中都能找到。尽管如此我还是摘抄下来,因为后面本老爹给出了一个有趣的例子。之后本老爹解释了一段经典helloworld程序中每个字符的意思.这里对于稍微接触过C++的人来说应该都没什么好看的。

Every name and every expression has a type that determines the operations that may be performed on it
A declaration is a statement that introduces a name into the program. It specifies a type for the named entity:
• A type defines a set of possible values and a set of operations (for an object).
• An object is some memory that holds a value of some type.
• A value is a set of bits interpreted according to a type.
• A variable is a named object

这里很清楚的说明了一个"名字"或者说id-expression,和表达式都有其类型来指定它所能执行的操作。也就是说表达式也有其类型。声明是向程序中引入一个名字,这个名字指代所声明类型的实体.这里更细致的说明可能要引入标识符(identifier)的概念,不过对初学者可能没有必要。剩下五句解释很简单,不过其中引入了对象的概念,不过这里本老爹似乎是因为前文叙述了阅读此部分的要求而没有解释。

Each fundamental type corresponds directly to hardware facilities and has a fixed size that determines the range of values that can be stored it

这里没什么好说的每个基础类型都有其硬件表示。不过这里如果不是基本类型似乎可以扩展到值表示对象表示的概念上。

A char variable is of the natural size to hold a character on a given machine (typically an 8-bit byte), and the sizes of other types are quoted in multiples of the size of a char. The size of a type is implementation-defined (i.e., it can vary among different machines) and can be obtained by the sizeof operator; for example, sizeof(char) equals 1 and sizeof(int) is often 4

这一大段我认为很重要也很容易被人忽略。直接说就是char类型所占用字节数是由实现定义的,不过通常为8。也有例外,有些平台一个char类型占9个字节比如PDP-11。c++为了实现其兼容性这里不作规定似乎是很重要的一点。每个类型都为char类型大小的整数倍, 这里似乎能为unsigned char数组作存储重用和进行类型转换埋下伏笔。

之后介绍了c++基本类型所能做的操作,也简单的介绍了一下类型转换,即在不同类型进行赋值和计算操作时,类型会做相应的转换。

double d = 2.2; //初始化浮点数
+c++编程语言第四版
Skip to content

c++编程语言第四版

3683字约12分钟

2024-11-02

c++之旅

导言

本文是The Cpp Programming Language 4th edition的学习记录

If you find this "lightning tour" confusing, skip to the more systematic presentation starting in Chapter 6

总的来说前五张只是速览,并不该纠结于细节问题

The Basics

首先一如其他编程或计算机书籍一样,一个从源码到可执行文件的流程图介绍。不过这里本老爹也借此重申了所谓c++的兼容性

When we talk about portability of C++ programs, we usually mean portability of source code; that is, the source code can be successfully compiled and run on a variety of systems

也就是说谈论兼容性说的是源码兼容,一份符合c++标准的源码应该可以保证在任何所支持平台和对应版本的编译器编译的。尽管这是常识,不过我还是写这里用作提醒。 然后本老爹引入一个名词实体

The ISO C++ standard defines two kinds of entities:
• Core language features, such as built-in types (e.g., char and int) and loops (e.g., for-statements and while-statements)
• Standard-library components, such as containers (e.g., vector and map) and I/O operations (e.g., << and getline())

不过这里和cppreference所述的实体有些出入。我不知为何*语句(statement)*也被划入实体的范畴。不过相比"对象"这个概念,实体确实很少有人去讨论或表述。就我的理解实体就是在c++程序中能被操作或识别的事物。他是真实存在的概念但不必通过占用内存,执行操作之类事件观测他的存在。

C++ is a statically typed language. That is, the type of every entity (e.g., object, value, name, and expression) must be known to the compiler at its point of use. The type of an object determines the set of operations applicable to it

我觉得这是很有用的一句话。因为接受这句话或许能帮助我解决初学c++时期的一些困惑。我个人认为它和我之后所认识到的严格别名优化或通过union进行类型转换所造成的UB相关。

Every C++ program must have exactly one global function named main(). The program starts by executing that function. The int value returned by main(), if any, is the program’s return value to "the system." If no value is returned, the system will receive a value indicating successful completion.

这段话或许能从所有c++相关书籍中都能找到。尽管如此我还是摘抄下来,因为后面本老爹给出了一个有趣的例子。之后本老爹解释了一段经典helloworld程序中每个字符的意思.这里对于稍微接触过C++的人来说应该都没什么好看的。

Every name and every expression has a type that determines the operations that may be performed on it
A declaration is a statement that introduces a name into the program. It specifies a type for the named entity:
• A type defines a set of possible values and a set of operations (for an object).
• An object is some memory that holds a value of some type.
• A value is a set of bits interpreted according to a type.
• A variable is a named object

这里很清楚的说明了一个"名字"或者说id-expression,和表达式都有其类型来指定它所能执行的操作。也就是说表达式也有其类型。声明是向程序中引入一个名字,这个名字指代所声明类型的实体.这里更细致的说明可能要引入标识符(identifier)的概念,不过对初学者可能没有必要。剩下五句解释很简单,不过其中引入了对象的概念,不过这里本老爹似乎是因为前文叙述了阅读此部分的要求而没有解释。

Each fundamental type corresponds directly to hardware facilities and has a fixed size that determines the range of values that can be stored it

这里没什么好说的每个基础类型都有其硬件表示。不过这里如果不是基本类型似乎可以扩展到值表示对象表示的概念上。

A char variable is of the natural size to hold a character on a given machine (typically an 8-bit byte), and the sizes of other types are quoted in multiples of the size of a char. The size of a type is implementation-defined (i.e., it can vary among different machines) and can be obtained by the sizeof operator; for example, sizeof(char) equals 1 and sizeof(int) is often 4

这一大段我认为很重要也很容易被人忽略。直接说就是char类型所占用字节数是由实现定义的,不过通常为8。也有例外,有些平台一个char类型占9个字节比如PDP-11。c++为了实现其兼容性这里不作规定似乎是很重要的一点。每个类型都为char类型大小的整数倍, 这里似乎能为unsigned char数组作存储重用和进行类型转换埋下伏笔。

之后介绍了c++基本类型所能做的操作,也简单的介绍了一下类型转换,即在不同类型进行赋值和计算操作时,类型会做相应的转换。

double d = 2.2; //初始化浮点数
 int i = 7; // 初始化整数
 d = d+i; // 求和赋值给d
 i=d∗i; // 将产生的值赋值给i(将双精度浮点数截断转换为整型)

C++ offers a variety of notations for expressing initialization, such as the = used above, and a universal form based on curly-brace-delimited initializer lists

简单的说c++提供了花括号初始化器,是得我们在初始化变量时(定义),可以这么写

double d1 = 2.3;
@@ -72,4 +72,4 @@
 }
 }
 Traffic_light light=Traffic_light::red;
-Traffic_light next = ++light; // next becomes Traffic_light::green;

模块化,分离编译,命名空间,错误处理,异常略过。

不变式(Invariants)

程序运行中一直保持为真的前提条件。比如上诉原文异常标题下,使用异常捕获out_of_range。程序运行中数组的索引始终处于[0,size)范围内,或 elme始终是指向 double [size]的指针,类似这样的陈述这就是类中的不变式。不变式的概念是c++中通过构造和析构函数管理内存的基本概念。

Often, a function has no way of completing its assigned task after an exception is thrown.Then, "handling"an exception simply means doing some minimal local cleanup and rethrowing the exception

通常函数无法完成分配任务时需要抛出异常,并且处理剩余的清理工作。异常是RAII的关键概念。

静态断言略过。

\ No newline at end of file +Traffic_light next = ++light; // next becomes Traffic_light::green;

模块化,分离编译,命名空间,错误处理,异常略过。

不变式(Invariants)

程序运行中一直保持为真的前提条件。比如上诉原文异常标题下,使用异常捕获out_of_range。程序运行中数组的索引始终处于[0,size)范围内,或 elme始终是指向 double [size]的指针,类似这样的陈述这就是类中的不变式。不变式的概念是c++中通过构造和析构函数管理内存的基本概念。

Often, a function has no way of completing its assigned task after an exception is thrown.Then, "handling"an exception simply means doing some minimal local cleanup and rethrowing the exception

通常函数无法完成分配任务时需要抛出异常,并且处理剩余的清理工作。异常是RAII的关键概念。

静态断言略过。

\ No newline at end of file diff --git a/docs/.vuepress/dist/article/jaovy4gg/index.html b/docs/.vuepress/dist/article/jaovy4gg/index.html index 72e768e..881e053 100644 --- a/docs/.vuepress/dist/article/jaovy4gg/index.html +++ b/docs/.vuepress/dist/article/jaovy4gg/index.html @@ -1,4 +1,4 @@ -搭建vscode-cpp环境
Skip to content

搭建vscode-cpp环境

1157字约4分钟

2024-07-03

VSCode 搭建cpp环境

准备工作

1.下载VScode 2.Windows环境下载mingw64
下载链接
3.解压缩x86-64 w64-mingw32
4.D:\workfile\gcc15\x86_64-w64-mingw32\bin
D:\workfile\gcc15\x86_64-w64-mingw32\lib
D:\workfile\gcc15\x86_64-w64-mingw32\lib32 添加至用户环境变量PATH
5.打开下载c++插件

Cmake搭配Vscode

前提介绍

1.CMakePresets.json:用于指定整个项目的构建细节,json中包含

name
+搭建vscode-cpp环境
Skip to content

搭建vscode-cpp环境

1157字约4分钟

2024-07-03

VSCode 搭建cpp环境

准备工作

1.下载VScode 2.Windows环境下载mingw64
下载链接
3.解压缩x86-64 w64-mingw32
4.D:\workfile\gcc15\x86_64-w64-mingw32\bin
D:\workfile\gcc15\x86_64-w64-mingw32\lib
D:\workfile\gcc15\x86_64-w64-mingw32\lib32 添加至用户环境变量PATH
5.打开下载c++插件

Cmake搭配Vscode

前提介绍

1.CMakePresets.json:用于指定整个项目的构建细节,json中包含

name
 预设的名称,一般用表示平台或编译期的版本名字;
 
 vendor
@@ -87,4 +87,4 @@
 add_executable(main ${src_list})
 
 # 把目标文件与库文件进行链接
-target_link_libraries(main ${TESTFUNC_LIB})

PRIVATE 关键字表明 fmt 仅在生成 HelloWorld 时需要,不应传播到其他依赖项目

cmake 命令速览

cmake -Bbuild -GNinja -S. 以ninja生成 以 当前目录为源码 构建目录为build(如果没有就新建)

cmake -Bbuild -GNinja -S.. 在build文件夹下执行

ninja 在build文件夹下执行

贡献者: ImoutoCon1999
\ No newline at end of file +target_link_libraries(main ${TESTFUNC_LIB})

PRIVATE 关键字表明 fmt 仅在生成 HelloWorld 时需要,不应传播到其他依赖项目

cmake 命令速览

cmake -Bbuild -GNinja -S. 以ninja生成 以 当前目录为源码 构建目录为build(如果没有就新建)

cmake -Bbuild -GNinja -S.. 在build文件夹下执行

ninja 在build文件夹下执行

贡献者: ImoutoCon1999
\ No newline at end of file diff --git a/docs/.vuepress/dist/blog/archives/index.html b/docs/.vuepress/dist/blog/archives/index.html index d4cfea3..501712c 100644 --- a/docs/.vuepress/dist/blog/archives/index.html +++ b/docs/.vuepress/dist/blog/archives/index.html @@ -1 +1 @@ -归档
Skip to content

Yuzhiy

Yuzhiy

我心匪石不可转,我心匪席不可卷

anhui

\ No newline at end of file +归档
Skip to content

Yuzhiy

Yuzhiy

我心匪石不可转,我心匪席不可卷

anhui

\ No newline at end of file diff --git a/docs/.vuepress/dist/blog/categories/index.html b/docs/.vuepress/dist/blog/categories/index.html index 6fe33bb..6d64db9 100644 --- a/docs/.vuepress/dist/blog/categories/index.html +++ b/docs/.vuepress/dist/blog/categories/index.html @@ -1 +1 @@ -分类
Skip to content

Yuzhiy

Yuzhiy

我心匪石不可转,我心匪席不可卷

anhui

\ No newline at end of file +分类
Skip to content
\ No newline at end of file diff --git a/docs/.vuepress/dist/blog/index.html b/docs/.vuepress/dist/blog/index.html index 8e072fe..8a1d68c 100644 --- a/docs/.vuepress/dist/blog/index.html +++ b/docs/.vuepress/dist/blog/index.html @@ -1 +1 @@ -博客
Skip to content

Yuzhiy

Yuzhiy

我心匪石不可转,我心匪席不可卷

anhui

\ No newline at end of file +博客
Skip to content

Yuzhiy

Yuzhiy

我心匪石不可转,我心匪席不可卷

anhui

\ No newline at end of file diff --git a/docs/.vuepress/dist/blog/tags/index.html b/docs/.vuepress/dist/blog/tags/index.html index f2fc377..fd006cb 100644 --- a/docs/.vuepress/dist/blog/tags/index.html +++ b/docs/.vuepress/dist/blog/tags/index.html @@ -1 +1 @@ -标签
Skip to content

标签

Yuzhiy

Yuzhiy

我心匪石不可转,我心匪席不可卷

anhui

\ No newline at end of file +标签
Skip to content

标签

Yuzhiy

Yuzhiy

我心匪石不可转,我心匪席不可卷

anhui

\ No newline at end of file diff --git a/docs/.vuepress/dist/index.html b/docs/.vuepress/dist/index.html index 2e9bc52..cbd6939 100644 --- a/docs/.vuepress/dist/index.html +++ b/docs/.vuepress/dist/index.html @@ -1 +1 @@ -
Skip to content

Yuzhiy

Cpp Developer

我心匪石不可转,我心匪席不可卷

\ No newline at end of file +
Skip to content

Yuzhiy

Cpp Developer

我心匪石不可转,我心匪席不可卷

\ No newline at end of file diff --git a/docs/.vuepress/dist/sitemap.xml b/docs/.vuepress/dist/sitemap.xml index aad5205..b671f21 100644 --- a/docs/.vuepress/dist/sitemap.xml +++ b/docs/.vuepress/dist/sitemap.xml @@ -1,3 +1,3 @@ -https://github.com/2024-11-04T09:00:14.000Zdailyhttps://github.com/article/027o3g1x/2024-11-03T13:53:48.000Zdailyhttps://github.com/article/j3qgcpng/2024-11-03T13:53:48.000Zdailyhttps://github.com/article/d3sghq29/2024-12-04T09:01:14.000Zdailyhttps://github.com/article/72dkdlbu/2024-12-04T09:01:14.000Zdailyhttps://github.com/article/xst10xfz/2024-12-02T15:54:51.000Zdailyhttps://github.com/article/vqkwmfa2/2024-12-05T09:01:36.000Zdailyhttps://github.com/article/j3e883z1/2024-12-02T15:54:51.000Zdailyhttps://github.com/article/wpu7x9jw/2024-12-02T15:54:51.000Zdailyhttps://github.com/data_struct/map_str/2024-12-02T15:54:51.000Zdailyhttps://github.com/data_struct/2024-12-02T15:54:51.000Zdailyhttps://github.com/article/jaovy4gg/2024-12-02T15:54:51.000Zdailyhttps://github.com/math/mathformula/2024-12-02T08:48:44.000Zdailyhttps://github.com/math/2024-12-02T08:48:44.000Zdailyhttps://github.com/math/math/7ge8cr0s/dailyhttps://github.com/test1/chapter3-4/2024-12-02T08:48:44.000Zdailyhttps://github.com/test1/exception/2024-12-02T08:48:44.000Zdailyhttps://github.com/test1/2024-12-02T08:48:44.000Zdailyhttps://github.com/blog/dailyhttps://github.com/blog/tags/dailyhttps://github.com/blog/archives/dailyhttps://github.com/blog/categories/daily \ No newline at end of file +https://github.com/2024-11-04T09:00:14.000Zdailyhttps://github.com/article/j3qgcpng/2024-11-03T13:53:48.000Zdailyhttps://github.com/article/d3sghq29/2024-12-04T09:01:14.000Zdailyhttps://github.com/article/72dkdlbu/2024-12-04T09:01:14.000Zdailyhttps://github.com/article/xst10xfz/2024-12-02T15:54:51.000Zdailyhttps://github.com/article/027o3g1x/2024-11-03T13:53:48.000Zdailyhttps://github.com/article/oy4qci0t/2024-12-09T15:37:00.000Zdailyhttps://github.com/article/j3e883z1/2024-12-09T15:37:00.000Zdailyhttps://github.com/article/pc9qmrqh/2024-12-09T15:37:00.000Zdailyhttps://github.com/article/wpu7x9jw/2024-12-02T15:54:51.000Zdailyhttps://github.com/article/vqkwmfa2/2024-12-05T09:01:36.000Zdailyhttps://github.com/data_struct/map_str/2024-12-02T15:54:51.000Zdailyhttps://github.com/data_struct/2024-12-02T15:54:51.000Zdailyhttps://github.com/article/jaovy4gg/2024-12-02T15:54:51.000Zdailyhttps://github.com/math/mathformula/2024-12-02T08:48:44.000Zdailyhttps://github.com/math/2024-12-02T08:48:44.000Zdailyhttps://github.com/math/math/7ge8cr0s/2024-12-09T15:37:00.000Zdailyhttps://github.com/test1/chapter3-4/2024-12-02T08:48:44.000Zdailyhttps://github.com/test1/exception/2024-12-02T08:48:44.000Zdailyhttps://github.com/test1/2024-12-02T08:48:44.000Zdailyhttps://github.com/blog/dailyhttps://github.com/blog/tags/dailyhttps://github.com/blog/archives/dailyhttps://github.com/blog/categories/daily \ No newline at end of file diff --git a/docs/.vuepress/public/images/tools/vscode_clang_vscodepre1.png b/docs/.vuepress/public/images/tools/vscode_clang_vscodepre1.png new file mode 100644 index 0000000..8866266 Binary files /dev/null and b/docs/.vuepress/public/images/tools/vscode_clang_vscodepre1.png differ diff --git a/docs/.vuepress/public/images/tools/vscode_clang_vscodepre2.png b/docs/.vuepress/public/images/tools/vscode_clang_vscodepre2.png new file mode 100644 index 0000000..730f897 Binary files /dev/null and b/docs/.vuepress/public/images/tools/vscode_clang_vscodepre2.png differ diff --git a/docs/.vuepress/theme.ts b/docs/.vuepress/theme.ts index 962bada..56e66a9 100644 --- a/docs/.vuepress/theme.ts +++ b/docs/.vuepress/theme.ts @@ -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, diff --git a/docs/tools/vscode_clang.md b/docs/tools/vscode_clang.md index 9dd7d14..f8c31b9 100644 --- a/docs/tools/vscode_clang.md +++ b/docs/tools/vscode_clang.md @@ -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 @@ -71,3 +216,5 @@ ninja -t clean 清除构建文件 ninja <目标> 编译对应项目 有时你的引入的库依赖太多文件 此时只构建你的目标文件 ninja -v 详细模式构建所有目标 + +