Table of contents
3. Linux project automation build tool - make/Makefile
4. Linux package manager - yum
Foreword: Due to space reasons, this article focuses on listing the commands. Friends, go down and try it yourself. Only by using it more can you really remember it!
1. Linux editor - use vim
vim is a multi-mode editor
——command mode ( the mode opened by default )
-Edit/Insert mode (enter i) (enter ESC to return to command mode)
——Bottom line mode (enter shift + :) (enter ESC to return to command mode)
- replace mode (shift+r)
Common commands: (The ones in parentheses are equivalent to explanations, which are not required when entering commands)
yy: copy the line where the current cursor is located, nyy (n represents a specific number, copy n lines)
p: Paste the copied line np (copy n times)
dd: Cut (delete) the line where the current cursor is located ndd (delete n lines) + p (delete paste -> cut)
u: undo operation
ctrl+r: undo u operation
shift+g: the cursor is positioned at the end of the file
n+shift+g: the cursor is positioned on any line of the file
gg: the cursor is positioned at the very beginning of the file
shift+6 (^): Position the cursor to the very beginning of the current line
shift+4 ($): position the cursor to the end of the current line
w,b: Move the cursor back and forth in word units (after w, before b)
h, j, k, l: left, down, up, right
shift+~: switch case
shift+r: enter replacement mode
r: replace the character where the cursor is nr (replace n characters)
x: delete the character where the cursor is (from left to right) nx (delete n characters)
shift+x (X) : Delete the character where the cursor is located (from right to left)
Bottom line mode: (Which screen the cursor is on is the bottom line of the file)
set nu: display line number
set nonu: cancel the line number
vs filename: split-screen operation
w: write w! force write
q: Quit q! Force quit
ctrl+w+w: multi-split screen switching cursor
!cmd (cmd is an execution command): Execute the corresponding command without exiting vim (execute command line, compile, allow, view man), etc.
Visual mode: ctrl+v (to be added)
Multi-line comments for vim:
In the command mode, ctrl+v enters the visualization mode
Use hjkl to select the desired block
shift+i to enter insert mode
//Enter comments, press Esc to implement multi-line comments
Vim cancels multi-line comments:
In the command mode, ctrl+v enters the visualization mode
Use hjkl to select the desired block
Press x or d directly to delete directly, and then press Esc to exit
2. Linux compiler - gcc/g++
g++ did not enter the command:
sudo yum install -y gcc-c++
gcc did not enter the command:
sudo yum install -y gcc
gcc is a compiler specially used to compile and link c language
The process of program translation:
Text C -> Computer Binary
1. Preprocessing (a. remove comments b. macro replacement c. header file expansion d. conditional compilation...)
——Is it still C language after preprocessing?
Answer: or C language
2. Compile (C->Assembly)
3. Assembly (Assembly -> Redirectable Binary Object File)
4. Link (link -> multiple .o, .obj -> merge to form one executable).exe
View version:
gcc -v
g++ -v
gcc source file -o executable file #form executable file
Or it can be written like this: gcc -o executable source file
Preprocessing:
#-E: Start the translation of the program from now on, stop if the preprocessing is complete!
gcc -E source file -o temporary file.i (preprocessing file)
Compile:
#-S: Translate the program from now on, stop if the compilation is complete!
gcc -S tempfile.i -o tempfile.s
compilation:
#-c: Translate the program from now on, stop if the compilation is complete!
gcc -c temporary file.s -o redirectable executable.o (binary)
Link:
gcc .o file -o executable program
Dynamic and static library:
ldd executable program - view library
file executable program - check what link method is used
There are two general methods of linking:
a. Dynamic link - requires dynamic library (.so) under windows: .dll
b. Static link - requires a static library (.a) under windows: .lib
Dynamic link: Fill in the address of the method I want in the library into my executable program and establish an association! (save resources)
Static link: copy the implementation of the method in the library to our executable program! (Occupy resources)
The executable programs formed by gcc and g++ are dynamically linked by default!
How to link statically? Add—static!
-static: Indicates that an executable program is formed by static linking!
Your machine may fail to link because there is no static library!
Dynamic link must use .so dynamic library file
Static link must use .a static library file
sudo yum install -y glibc-static #C静态库
sudo yum install -y libstdc++-static #C++静态库
3. Linux project automation build tool - make/Makefile
make is a command
Makefile is a file
Existence value: automated construction projects
Write Makefile: a. Dependency b. Dependency method
make scans from top to bottom, and only automatically forms the first encountered target
To generate the following: make target
.PHONY is always executed!
- will always execute dependent methods according to dependencies!
—— Habit: set .PHONY for clean
How does the Makefile know that our executable is up to date? ?
——According to the modification time of the file ( comparing the time of the executable program and the source file, if the time of the source file is later than the executable program, make will be executed )
Access: access time
Modify: content modification time
Change: attribute modification time
Multi-file Makefile:
Results of the:
4. Linux package manager - yum
1. Is the software you want to download and install on your computer?
No, it is in the software development platform
2. If not, how do you know where it is?
I don't know, yum knows
3. Who released it?
Linux community or corresponding developers
The role of yum: a. Search, download, install b. Resolve dependencies
Generally, the native Linux system, the built-in download link is basically its own supporting foreign website
yum operation
yum source: a configuration file
查看yum源:ls /etc/yum.repos.d
Yum three tricks:
1. #yum list | grep xxxx to find the yum list
2.#sudo yum install -y install software
3. #sudo yum remove your software #remove
git - version controller
Reina Stovas, take it upon yourself to write a version controller! ——git
git three tricks:
#git clone your git warehouse link
1.#git add your file #Add our code to the local warehouse, git add. Put all the files to the local warehouse
2.#git commit -m "The commit log must be written here"
3.#git push #Submit our code to the remote warehouse
git log #View submission records
Conflict resolution:
git pull #sync
Prevent some suffix files from being uploaded: in the .gitignore file
git rm # can be deleted
5. Linux debugger - gdb
The executable program formed by gcc and g++ by default searches for release! Therefore, it cannot be directly debugged! (default dynamic link formation)
To use gdb debugging, you must add the -g option when generating the binary program from the source code
gdb will record the last command, if the command has not changed, you can press Enter directly!
gdb command:
quit: quit
r: start debugging, if no breakpoint is set, it will run directly to the end!l: view codeb+line number: break point for a specific line numberinfo b: View breakpoints (including breakpoint numbers)d breakpoint number: delete breakpointn: Process by process, equivalent to F10 of VSp variable name: print variable contents: statement by statement, equivalent to F11 of VSbt: view the current call stackfinish: Stop after running the current functiondisplay: set long displayundisplay number: cancel long displayuntil: jump to the specified linec: Running to the next breakpoint will stop!number of disable/enable breakpoints: enable (turn off and on) breakpoints