Use of development tools in the Linux environment.

pigskin brothers 2022-09-23 08:04:15 阅读数:577

usedevelopmenttoolslinuxenvironment.

🧸🧸🧸各位大佬大家好,我是猪皮兄弟🧸🧸🧸
在这里插入图片描述

一、Linux编辑器-vim的使用

1.Edit and exit

vim //即可打开vim
vim XXX //to edit a file
: //也就是shift + ;,You can move the cursor to the lower left corner(底行模式)
输入wq //wcalled writing(保存),qquit
输入!wq //in the case of inability to write or exit,This means force write and force quit

2.vim的多种模式

vim是一款多模式的编辑器,vimIt is in command mode when first opened(The mode that is turned on by default),To write code, you need to switch modes

i/F12 //to switch to edit mode(Also called insert mode)
ESC(exit screen) //回到命令模式

a.命令模式

命令模式NORMAL

yy //Copy the current line
nyy //从当前行开始,复制n行
dd //剪切
ndd //从当前行开始,剪切n行
p //粘贴
u //撤销
Ctrl r//撤销撤销
file as long as it doesn't exit,You can even save itu和Ctrl r,But once you quit it doesn't work
G //光标定位到文件结尾
gg //光标定位到文件开始
n G //The cursor is positioned on any line
$/shift 4 //Position to the end of the text line
^/shift 6 //Navigate to the beginning of a line of text
h //向左移动 ↑
j //向下移动 ↓
k //向上移动 ↑
l //向右移动 →
r 某字母 //Replace the character at the current position with a character
nr 某字母 //from the current locationn个替换成某个字符
x //Delete the current self character
shift ~ //Case replacement for a single letter(自动替换,无需输入)
shift r //Convert to replacement mode,Overwrite replacement regardless of current content,It's ok if you make a mistakeBackspace回退

b.底行模式

底行模式COMMAND

set nu //设置行号
set nonu //取消设置行号
vs 文件名 //vim分屏操作,Which split screen the cursor is on,Who is the bottom row
Ctrl ww //切换分屏,注意,This is the command for bottom line mode
! //不退出vim执行命令
!ls -al
!man ls
!gcc -o test test.c等等

在这里插入图片描述

c.替换模式

shift r Switch to replace mode
F12/insert to switch to replacement mode,You can also switch to insert/编辑模式

二、Linux编译器-gcc/g++的使用

gcc是专门用来编译C语言的编译器
g++是用来编译C/C++的编译器(因为C++兼容C)

gcc -v
g++ -v //查看版本

gcc是默认有的,如果g++没有的话sudo yum install -y gcc-c++

1.gcc

There are actually four processes for compiling and linking:预编译、编译、汇编、链接

预编译: 主要进行
1.去注释2.宏替换3.头文件展开4.条件编译
总的来说也就是去注释处理预处理指令

gcc -E test.c -o test.i
-EDelegate to stop after preprocessing is over,生成的是test.i文件
-oYes I want to assign a new name
.i是LinuxThe file suffix of the file generated after preprocessing

编译:主要是将Clanguage is replaced with assembly language
Among them is semantic analysis,语法分析,词法分析,词义分析 ,符号汇总等等

gcc -S test.c -o test.s
-SIndicates to stop after compilation,生成的是test.s文件
-oIndicates the specified name
.s是LinuxThe file suffix of the files generated after compilation

汇编: Mainly replace assembly language with binary language and form symbol table
The result is a redirectable binary object file

gcc -c test.c -o test.o
-cIndicates to stop after compiling,生成的是.o文件
-oIndicates to reformulate a name
.o是LinuxThe file suffix of the file generated after assembly

链接: Multiple executables generate executables through the linker
And includes relocations that form the segment table and symbol table

gcc test.o -o test
gcc test.c -o test
//直接gccis to compile the link

2.g++

过程类似,参考gcc自己琢磨

三、动静态库&&动静态链接

1.动静态库

ldd XXX //List the dynamic library dependencies of a file
file XXX //LinuxThe following is not a suffix name to determine the type of a file,因此我们可以用fileto see the type of a file

在这里插入图片描述
在这里插入图片描述

There are two general ways of linking
一种是动态链接,A dynamic library is required
一种是静态链接,A static library is required

我们用ls /lib64You can see a large number of dynamic and static libraries
比如调用printf函数,It is provided by these dynamic and static libraries
Find the declaration of the method through the header file,Then find the implementation of the method through the library,And then somehow link my code to the code in the library,An executable program is formed

Linux:
.so (动态库)
.a (静态库)
Windows:
.dll (动态库)
.lib (静态库)

2.动静态链接

**动态链接:**The address of the implementation method that will be required in the library,填入我的可执行程序中,建立关联
好处:节省资源
坏处:Very dependent on library files,If not present or missing,程序无法运行

**静态链接:**将库中方法的实现,copied into the executable program
好处:No longer depend on libraries
坏处:占用资源

3.Actual static linking

gcc、g++The executable program formed by default is dynamically linked
在这里插入图片描述

gcc test.c -o test -static
-static Indicates the use of static linking to form executable programs

By default, the cloud service only adds dynamic libraries,需要自己安装

sudo yum install libstdc++-static
sudo yum install glibc-static

在这里插入图片描述
由此可见,Static linking is very resource intensive,The dynamic link takes up less

四、Linux项目自动化构建工具-make、Makefile

make是命令,Makefile是文件
make和makefileThe meaning of existence is to automatically help us build projects
makefile文件的内容就是
a.依赖关系
b.依赖方法

在这里插入图片描述
其中,test.c是依赖关系,gcc test.c -o mytestis a dependent method
.PHNOY:clean是伪目标

.PHONY是一个关键字,Pseudo goals are characterized by always being executed(多次被执行)
在这里插入图片描述

So how does the compiler know about metestis the latest yet?
We talked about it in the previous article,ACMThe last modification time in time
The compiler compares the time of the generated executable program with the time of the source program,If the executable program is the latest,Then it's the latest
在这里插入图片描述
A:access最近访问时间,Modification is also an access,Not the time to open the file
C: change最近修改的时间(属性的改变)
M: modify最近修改的时间(内容的改变)
文件=内容+属性
Visits are a high-frequency event,If you visit once, modify it once,大大降低了效率,所以,LinuxIt is accumulated for a certain period of time before modifying the access time

Multiple source files form an executable program

gcc -o mytest main.c test.c

Makefile文件

mytest:main.o test.o //(依赖关系列表)
gcc -o mytest main.o test .o//When a top-down scan cannot find neutralize two files,继续向下扫描
main.o:main.c
gcc -c main.c -o main.o
test.o:test.c
gcc -c test.c -o test.o
.PHONY:clean
clean:
rm -rf *.o mytest

感谢大家的支持,我会持续更新!!!
在这里插入图片描述

copyright:author[pigskin brothers],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/266/202209230724172424.html