【Linux】vim、gcc、Makefile

[Linux] development tools and the use of (vim, gcc, Makefile)

The first to use the tool to have vim, gcc, Makefile and so on.

Vim and gcc

1. vim
mainly describes the three modes of vim (in fact, there are a lot of models, the current understanding of these three can be), are command mode (command mode), insert mode (Insert mode) and the bottom line mode (last line mode), functional distinction model is as follows:
normal / normal / command mode (normal mode)
control delete screen cursor movement, character, word, or row, and move into the lower section of a copying insert mode, the last line mode or
the insertion mode ( Insert mode)
only in Insert mode, it can be done entering text, press the "ESC" key to return to the command line mode. This mode is the most frequently behind us with the
editing mode.
Line mode (last line mode)
save the file or exit, can also replace a file, looking for strings, lists the line number and other operations. In the command mode, shift +: to enter the mode
type. To see all your patterns: open vim, the bottom line mode Direct input: help vim-modes
basic operation of 2.vim
enter vim, after the system prompt and enter the file name of vim, vim to enter full-screen editing screen:
$ vim test.c
but one thing to pay special attention to, that is, after you enter the vim, is in the [normal mode], you have to switch to [insert mode] to be able to input text
characters.
[Normal mode] is switched to [insert mode]
Input a
input i
input o [insert mode] is switched to [Normal mode]
Currently in [insert mode], can only have been to enter text, if you find a word wrong, wanted to move back with the cursor keys, delete the word can be
to first click the "ESC" key to [Normal mode] and then deleted text. Of course, you can delete it.
[Normal Mode] switch to [line mode] "shift +;" in fact, enter ":"
Quit vim and save the file in the [normal mode], click the ":" colon key to enter the "Last line mode" for example:
: w (save the current file)
bit Technology
: wq (enter "wq", save and quit vim)
:! q (input q !, force quit without saving vim)
2.gcc
format gcc [options] file to compile [options] [destination file]
pretreatment (macro replacement)
preprocessing functions including macro definitions file contains, conditional compilation, and the like to comment.
Preprocessing instruction is the beginning of the line number #.
Examples: gcc -E hello.c -o hello.i
option "-E", the role of this option is to allow gcc compiler stops at the end of the pretreatment process.
Option "-o" refers to the target file, ". I" file as C original program has been pretreated.
Compile (generate an assembly)
at this stage, gcc should first check the specification of the code, if there are grammatical errors, work to be done to determine the actual code, checking
and correct, gcc translate the code into assembly language.
Users can use the "-S" option to view, this option is only compiled without compilation, generate assembly code.
Examples: gcc -S hello.i -o hello.s
Assembler (machine-generated identification code)
compilation stage is to generate a compilation phase of ".s" file into the target file
reader can use this option "-c" you can see the assembly code has been transformed into ".o" binary the object code
examples: gcc -c hello.s -o hello.o
connection (generate an executable file or library file)
after a successful compile, link entered the stage.
Examples: gcc hello.o -o hello
library of static and dynamic library (focus)
static library refers to when compiling the link, the code library file all added to the executable file , the generated files are large, but at runtime also
no longer needed library files. Its extension is generally ".a"
dynamic libraries contrast, when you compile and link the code library file is not added to the executable file, but by the runtime when the program is executed
to load the library link files , so you can save system overhead . DLL generally suffix ".so", as previously libc.so.6 is the dynamic
libraries. gcc default dynamic library at compile time. After completion of the link, gcc can generate an executable file, as shown below. gcc
hello.o -o the Hello
gcc default binary program is dynamically linked.

Linux project build automation tool -make / Makefile

1. Why use Makefile? (Interview test sites)
source file in a project does not count, according to its type, function modules were placed in several directories, makefile defines a set of rules to specify which files need to be compiled , after which files need to compile, which files need to be recompiled, even more complex functions. ( Many large projects are compiled by Makefile organized, if there is no Makefile, that a lot of projects in various dependencies between libraries and I do not know the code will be more complicated )
Makefile benefits is - "Automation compilation" Once written, you only need a make command, the whole project is fully automatic compiler, which greatly improves the efficiency of software development.
make is a command, makefile is a file, with the use of two complete building automation projects.
2. Project to clean up clean
project that need to be cleaned
as clean this, the first goal was not directly or indirectly related file, the command behind it will not be defined automatically,
but we can show to make execution . That command - "make clean", in order to remove all object files in order to reprogram
the translation.
But generally we clean this object file, we set it to false objects, with .PHONY modification, characteristic of the pseudo target is always
executed.

The process of writing programs

1. Check to see gcc and install vim
input vim command, view the version of vim
Here Insert Picture Description
input gcc -v to check whether the installation
Here Insert Picture Description
2.
Create a directory file mkdir fileand enter the file cd file
command statement: vi test..ccreated and written
Here Insert Picture Description
3. Press to enter the vim "i" from the command mode into the insert mode, coding
Here Insert Picture Description
after completion, press [enter] esc command mode, :wq
enter the line mode, save and exit
Here Insert Picture Description
at the same directory, create the Makefile vi Makefile
Here Insert Picture Description
same manner save exit
4. If the code is correct, the input command makeautomatically a compiled program, compiled input ./文件名generator
Here Insert Picture Description
5. when finished, enter the command make cleangenerated after clean up the build file test
Here Insert Picture Description
which it completed
last share two tips:
1. enter the command, directory or file name automatically press the [TAB] key completion
2. when stuck, the cursor disappears: no brains 【CTRL】+ c(we are most familiar with the buttons of the bar), if it is or not 【CTRL】+ z, the cursor still can not get out, then restart the virtual machine it (ha ha ha)

Published 12 original articles · won praise 42 · views 4204

Guess you like

Origin blog.csdn.net/qq_43676757/article/details/104942632