编程知识 cdmana.com

Common Linux tools

Vim Comparison with other editors

Emacs

  Emacs It's not just an editor , It's an integrated environment , Or it can be called the integrated development environment , These functions, such as putting users in a fully functional operating system .Emacs Not only can it be used as a text editor , It can also be used to send and receive e-mail 、 adopt FTP/TRAMP Edit remote files 、 adopt Telnet Log on to the host 、 Go to the newsgroup 、 land IRC Communicate with friends 、 View calendar and other functions

Eclipse

  Eclipse It's a cool open source editor , It has powerful functions such as code highlighting and intelligent prompt . stay Eclipse in , Fully competent in the following programming languages ——Python, R, Ruby, JavaScript, Natural, Lasso, C, C++, COBOL, Scheme, Clojure, Groovy wait , So is it Java Integrated development environment , It even provides a solution to Java 8 Support for . In some Web Development IDE With the help of features , You can easily organize and access code files

gcc Comparison with other compilers

Clang

  licence Extremely friendly , The quality of the code is great , Adopted IR by LLVM IR Excellent , Major companies are gradually making efforts in Clang On , Including but not limited to Microsoft ,IBM,Nvidia etc. , Companies are also starting to go crazy Clang / LLVM Cross code ( Enclosure ), Also began to go to Clang Realization OpenMP,Nvidia GPU Other support , It's catching up GCC On the road of passion all the way , The future is bright . however Clang Depend on LLVM, The current performance cannot match GCC It's a debate , stay Benchmark There are few winning projects in performance testing , The road to optimization is a long way to go , At the same time, some open source software can't be compiled , The main reason is the lack of knowledge of GCC some Builtin function 、 The weakness of its own assembler leads to

ICC

   Full name Intel C++ Compiler, yes Intel Developed C/C++/Fortran Compiler package , Apply to Linux、Microsoft and Mac OS X operating system , There is nothing wrong IA Instruction set version ( That is to say, only for x86 framework CPU Use ).ICC Widely used in high performance computing 、 Business Computing, such as distributed computing , Its vectorization and parallelization performance is the industry benchmark , Can give full play to the characteristics of modern processors

1. Editor Vim

  Vim It's from vi Developed a text editor . The default configuration is generally not able to meet people's requirements , So you have to configure it yourself , These configurations usually include a list of project structures , File structure list , Automatic jump , Automatic prompt and completion , Plug-in management , Syntax check , Plug ins like version control
  Vim Configure to be your own IDE:
     open /etc Under the table of contents vimrc or User directory vimrc Can be modified
     The former is to modify the system Vim To configure , All users can use this configuration
     The latter is to modify the user Vim To configure , Users have priority to use the configuration in the user directory
     You can find and download the relevant configuration package on the Internet ( Before the command to unzip the package, there was )
  Vim All in all 12 Operation modes , Commonly used 3 Kind of :
     Common mode
     Insertion mode
     End of line mode

Vim operation :

Enter normal mode : " esc "

Enter insertion mode :

i Insert in front of the cursor
I Insert at the beginning of the line
a Insert after the cursor
A Insert at the end of the line
o Open a new line down and insert the beginning of the line
O Open a new line up and insert the beginning of the line

Enter the end of line mode : " : "

shift + :
w Save
wq Save and exit
q! Exit Without Saving

Cursor movement ( In normal mode )

h Move left
j Move down
k Move upward
l Move right
M Move to the middle line
L The cursor moves to the beginning of the last line of the screen
^ Move the cursor to the beginning of the current line
I Move the cursor to the beginning of the current line and enter insert mode
$ The cursor moves to the end of the current line
A Move the cursor to the end of the current line and enter insert mode
G Move to specified row , Line number + shift + g
w Move back one word at a time
b Move forward one word at a time
{ Move by end , Move upward
} Move by end , Move down

Flip screen ( In normal mode )

ctrl + d Turn down half screen
ctrl + u Turn up half screen
ctrl + f Flip down one screen
ctrl + b Turn up one screen
gg The cursor moves the beginning of the file
G Move the cursor to the end of the file

gg To the beginning of the line , Press =,shfit + g Automatic typesetting of all code

The delete command ( In normal mode )

x Delete the character after the cursor
X Delete the character before the cursor
dd Delete entire line ,
n dd Delete the specified number of rows
D Delete all the contents of the line after the cursor is deleted
d0 Delete all the contents of the line before the cursor , Does not contain the cursor character
dw Delete the word at the beginning of the cursor , Contains the character where the cursor is

Revocation order ( In normal mode )

u Step by step
U Undo all operations of the current line at one time
ctrl + r Counter cancellation

Repeat the order ( In normal mode )

. Repeat the last command

Text lines moving ( In normal mode )

>> Move the text line to the right
<< Move the text line to the left

Copy and paste ( In normal mode )

YY Copy the current row
n yy Copy n That's ok
p Open a new line down the cursor , Paste

Visual Modes ( In normal mode )

v Move selected text by character
V Move by line , Select text visual mode to match d,y,>>,<< operation

Replace operation ( In normal mode )

r Replace the current character
R Replace the character after the current cursor

Split screen operation ( End of line mode )

sp Split up and down , You can affix the file name after
vsp Left and right split screen , You can affix the file name after
ctrl + w + w More windows to switch
perform shell Give orders Enter... In the end of line mode !, Followed by an order

Start split screen

vim -On file vim It's about time to start n Screens
vim -on file vim Start up and down n Screens

Turn off split screen

ctrl + w c Close the current window
ctrl + w q Close the current window , If there is only one left, exit vim

Set the split screen distance

ctrl + w n >> Current window widening n A unit of
ctrl + w n << The current window shrinks n A unit of

Search for commands

/ lookup , When you find it, press n You can go to the next

View command

shfit + k Move the cursor over the function , Check the configuration
In the end of line mode :
set nu According to the line Numbers
set nonu Turn off display line number
:! man Number of chapters Function name vim Let's look at the functions in chapters , Press q return vim

Compiler gcc

gcc / g++ : compiler
gcc : function
   take c/c++ Translate high-level language code into machine recognizable code
The build process :
   Preprocessing : Expand all code
   compile : Grammatical and semantic error correction , Translated into assembly code
   assembly : Translate assembly code into binary machine readable instructions
   link : Link library , Put all the code together to generate an executable program
   The library files :  Public code that has been assembled
   link : Take the code from the library into the executable program to be generated
   Static links : Link static libraries , Copy the code from the library directly to the executable program , The advantage is that the program does not rely on the existence of library files when it runs , The disadvantage is that it takes up more resources
   Dynamic links : Link dynamic library , It only records the location information of interface symbols in the library , The advantage is that the resource occupation is less redundant , The disadvantage is that the program needs the existence of dynamic library when it runs
  gcc Default link mode : Dynamic links

gcc command :

-v see gcc Version number
-I Specify the header directory , Followed by other orders ,gcc -I./include main.c dict.c -o app
-g Contains debugging information
-On n=0~3 Compile optimization ,n The bigger the optimization, the more
-Wall Prompt for more warning information
-D Define macros at compile time , Followed by other orders
-E Generating preprocessing files
-M Generate .c File and header dependency for Makefile, Include the header file of the system library
-MM Generate .c File and header dependency for Makefile, Does not include system library header files

Static library :

   Create a static library , Or add the object code to an existing static library :
  ar rcs libmylib.a file.o    Name with lib start , Followed by the name of the library .a
  nm libmyab.a        Look at the static library

Dynamic library ( Shared library ):

Shared library :
gcc -fPIC -c a.c     -fPIC : Generate location independent code -c : Only compile and generate .o file , Don't link
gcc -fPIC -a b.c
gcc -shared -Wl -o libmyab.so a.o b.o
gcc -share -Wl,-soname,libmyab.so.1 -o libmyab.so.1.0.1 a.o b.o
Generate libmyab.so.1.0.1
Pay attention to problems :
Introduce the header file containing the above four function declarations and compile it as follows
gcc main.c libmycal.so.1.10 -o app Successfully generated app But can't run
Use ldd app Name view app Which libraries to run on , Show libmyab.so.1
not found
sudo vim /etc/ld.so.conf Path to add library
sudo ldconfig -v Update configuration
Again ./app To run successfully
soname and linkname The difference between :
  soname The main version number of the library is recorded , By contrast app The main version number of the library determines whether it can be run on the corresponding machine
soname Is a symbolic link
Use... In the compile link phase :
  linkname No version information, just the name of the library , As the name suggests, in app The runtime will link to linkname Find the real library
  linkname Don't pay attention to version information , After changing the version of the library, you just need to change linkname Point to the new version library , You don't have to Makefile To modify the content of

Dynamic library & Advantages and disadvantages of static library

   Static library and app Compile together , In any Linux It can run under the system , But the size of the code is huge, and the shared library can run on other machines , Depending on whether the machine exists app The dependent library and the version number of the library , The advantage is that the code size is small

The debugger gdb

   function : Debug the running process of a program
Linux Under the program compiler default generation release Version program , Without debug symbol information , It means that the program can not be debugged, so the premise of program debugging is to compile and generate debug Version program , therefore gcc Compile the program with -g Options , Open the debug , Add debug symbol information to your program
   use gdb Before debugging and correcting errors, you must add “-g”,“-g” When compiling a program, it is often used to debug the program . We need to add this option to every source file that needs to be debugged . It will use a special version of C Language standard library completes compiling and linking operations , Add debugging support to library functions . The compiler will automatically pass these flags to the linker .
  readelf Commands are used to display one or more elf Format the target file information , You can control what information is displayed through its options . there elf-file(s) It means the files that are checked . Can support 32 position ,64 Bit elf Format file , It also supports the inclusion of elf The document of the document ( This generally refers to the use of ar Order some elf After the file is packaged, for example lib*.a And so on. “ Static library ” file ). This program and objdump The functions provided are similar , But it shows more specific information , And it doesn't depend on BFD library (BFD It's a GNU project , Its goal is to process different object files through a unified interface ), So even BFD What does the library have bug If it exists, it will not affect readelf Program . function readelf when , except -v and -H outside , One of the other options must be specified

yum install

yum Tools Install the software
yum : Package management tools
   Software installation method :
    1. Manual installation : Download the source code from the official website , Compile on your own machine , because
         Various possible dependencies , Different versions , It will lead to cumbersome installation , It's inefficient and can't even be installed at all
    2. Use tools to install : The tool itself can solve the dependency of package installation , Easy to use , Efficient
  yum Common operations :
   see : See what can be installed
    yum list
    yum list | grep package_name
   See what's already installed
    yum list installed | grep package_name
   install :
    yum install package_name
   remove :
    yum remove package_name

rmp install

linux Under the installation package for rpm Installation package . The usual installation method is :
  rpm -ivh The path of the package + Package name .rpm The parameter -i For installation -v display information -h Show progress bar . These three parameters are basically bundled rpm The path can be not only a local disk, but also ftp The directory of the server .
  rpm The disadvantage of installation is that many installation packages depend on each other , Big bag, small bag . Of course, there are corresponding parameters

The difference between the two

   comparison rpm In terms of installation yum The installation is more user-friendly .
  yum Installation does not need to consider dependencies, because it will find and install all the dependent packages involved in the package . If the computer is connected to the network, it will be more convenient to find dependencies from the network . And you don't have to think about software paths , because yum The software will find the corresponding software by downloading the source file

版权声明
本文为[Ran1366]所创,转载请带上原文链接,感谢

Scroll to Top