Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The use of vi and the process of gcc compilation

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1 text editing tool vi

  vi is the most commonly used text editor under Linux/Unix. Vim is an upgraded version of vi, which is not only compatible with all commands of vi, but also adds some new features.

1.1 three ways of working for vi

1.2 Editing mode cursor positioning

  M moves the cursor to the center of the page

  L moves the cursor to the end of the page

  H move the cursor to the beginning of the page

  Ctrl+f turns the page backwards

  Ctrl+b turn the page forward

  0 move the cursor to the beginning of the line

  $move the cursor to the end of the line

Copy, paste, delete

  nyy copies the downward n lines where the cursor is located

  p pastes the copied content at the cursor

  ndd deletes the contents of the downward n lines where the cursor is located

Undo and repeat

  u restores the previous action

 . Repeat the previous action

1.3 insert mode I and I keys insert: enter text at the current cursor, existing text will be backward

  An and a keys: a starts insertion from the next character of the current cursor, and A starts insertion from the last character of the line where the cursor is located

  O and o: insert a new line on the next line of the current cursor. O insert a new line on the previous line of the current cursor.

  R and r replace: r replaces the character where the cursor is located: r replaces the text where the cursor is located until ESC is pressed

1.4 Command mode

2 gcc

   gcc is the abbreviation of GNU Compiler Collection. Originally as a C language compiler, it now supports many languages, such as C, C++, Java, Pascal, Ada, COBOL and so on.

2.1 gcc compilation process

2.2 gcc common options

-o generate object code or executable file

-c informs gcc of the unlink step, that is, compiling the source code and finally generating the target file

-E runs only the C precompiler

-S tells the compiler to stop compiling after generating assembly language files, and the resulting assembly language files have the .s extension.

-Idir adds the dir directory to the directory path of the search header file

-Ldir adds the dir directory to the directory path of the search base

-llib link lib library

-g embed debugging information in the object file to facilitate debugging of debuggers such as gdb

-Wall causes gcc to warn against problems with the code of the source file

For example:

Gcc-E hello.c-o hello.i (preprocessing cpp)

Gcc-S hello.i-o hello.s (compile cc)

Gcc-c hello.s-o hello.o (assembly as)

Gcc hello.o-o hello (link ld)

-- "

Gcc-c hello.c or gcc-c hello.c-o hello.o (compile to generate object file)

-- "

Gcc hello.c-o hello (directly compiled and linked to an executable file)

3 gdb

   gdb is an acronym for GNU debugger and a programming and debugging tool

3.1 gdb usage

List (l) lists the source code

Break (b) set breakpoint

Info break View breakpoint information info functions

Run (r) running

Continue (c) continues to run the program until the next breakpoint

Step (s) single-step tracking, similar to step into in VC

Next (n) single-step trace, similar to step over in VC

Finish runs the program until the current function returns

Util (u) exit loop

Print (p) looks at runtime variables and expressions

Watch sets the observation point

Enter debug mode: gdb execution file (remember-g when gcc)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report