Linux under C Programming basics

Source: Internet
Author: User

1. Familiar with the development environment under Linux System 2. Familiar with the basic operation of VI 3. Familiar with the basic principles of the GCC compiler 4. Skilled use of the GCC compiler common options 5. Skilled use of GDB debugging technology 6. Familiar with makefile basic principles and grammatical specifications 7. Mastering the generation of static and dynamic libraries

One: Vim

1. Use the VIM command to enter the Vim interface$ vim practice_1.txt or vim 2. Cursor movement
Key Description
h Left
l Right (lowercase L)
j Under
k On
w Move to the next word
b Move to the previous word

3. Enter insert mode

Command Description
i Edit at current cursor
I Insert at beginning of line
A Inserting at the end of a row
a Insert an edit after the cursor
o Insert a new row after the current row
O Insert a new row before the current line
cw Replace the character from the position of the cursor to the end of a word

4. Save the document in command line mode

Enter the : command line mode from normal mode, enter w a carriage return, and save the document. Enter to save the :w 文件名 document as a different file name or save it to another path

5. Exit Vim

1. Exit vim in command line mode

Enter : command line mode from normal mode, enter wq return, save and exit edit

Here are a few other ways to exit:

Command Description
:q! Force quit, do not save
:q Exit
:wq! Force Save and exit
:w <文件路径> Save As
:saveas 文件路径 Save As
:x Save and exit
:wq Save and exit

2. Exiting vim in normal mode

Normal mode input Shift+zz can be saved out of vim

Practice:

One:

Two: Use Vim to enter the following code, contact use "K" to find the Help document:

I am not familiar with the usage of K.

Three: Practice GCC compile run code

GCC is divided into 4 steps:
Pretreatment:

GCC-E Hello.c-o hello.i

Compile:

Gcc-s Hello.i-o Hello.s

Assembly:

Gcc-c Hello.s-o hello.o

Link:

One: Static link

Ar rcsv LIPOW.A unsgn_pow.o

Gcc-o Pow_test.c-l.-lpow

./pow_test 2 10

Two: Dynamic Link

Gcc-fpic-wall-c unsgn_pow.c

Gcc-shared-o libpow.so UNSGN_POW.O

Gcc-o pow_test pow_test.c-l.-lpow

After repeated search for their own mistakes, and constantly correct, finally with GCC successfully compiled

Four: Practice GDB debugging Code

The programmer has several key hints:

    • The uppercase "K" can be used to find help for the function: Look at the man page, in command mode, place the cursor on the function name, press "K" to see the mans page directly.
    • Several settings

: Set NU Displays line number

: Set AI automatically indents rows

: Set ts=4 sets a TAB key equal to several spaces

    • Move cursor

[[Go to Previous ' {' in first column]

]] to go to the next "{" In the first column

{Go to previous empty row

} go to the next empty line

GD goes to the definition of the local variable referred to by the current cursor

Further study reference:

    • The concise Vim Practice level Introduction
    • Seven efficient text editing habits (for example, VIM) (video)
    • What you need: Use vim like the IDE
    • Vim Tutorials and learning materials Summary 3. Gccgnu CC (referred to as GCC) is an ANSI C-compliant compilation system in the GNU project that compiles programs written in languages such as C, C + +, and object C. GCC is also a cross-platform compiler that can develop software on the current CPU platform for a variety of hardware platforms of different architectures, so it is especially suitable for development in the embedded domain.

The process of compiling the code for GCC is as follows:

We can divide the compilation process into four steps to compile hello.c to generate executable Hello as an example, such as:

    • Preprocessing: Gcc–e hello.c–o hello.i;gcc–e Call CPP
    • Compilation: Gcc–s hello.i–o hello.s;gcc–s Call CCL
    • Compilation: Gcc–c hello.s–o hello.o;gcc-c Call as
    • Link: gcc hello.o–o hello; gcc-o call ld

The compilation process is difficult to remember, we simplify, the first three steps, GCC parameters linked to "ESc", the corresponding input file suffix is "ISO", so memory is much easier.

Another important point to learn about GCC is: reference materials, "in-depth understanding of computer systems" 7.6, 7.10, learning Static library, the production of dynamic library.

4. gdb

Recommended to use CGDB, better than GDB, familiar with the VC debugging methods, you can use DDD. Note Use GCC to compile with the "-G" parameter. Refer to the GDB Reference Card GDB's most basic commands are:

    • GdB Programm (Start gdb)
    • B Set Breakpoints (4 breakpoints are set: Line breakpoint, function breakpoint, conditional breakpoint, temporary breakpoint)
    • Run starts running the program
    • BT Print function Call stack
    • P View variable values
    • C continue running from the current breakpoint to the next breakpoint
    • N Single Step operation
    • S Single Step operation
    • Quit Quit GDB

Problem: GDB's n (next) command lets GDB execute the next line and then pause. The s (step) command acts like this, except that the step command enters the function when the function is called, so what should be preferred in actual use? Why?

A few other debug commands that I think should be mastered are:

    • Change of display tracking variable value
    • Until jump out of the loop
    • Finish Jump function
    • Help

Learning Reference:

    • Chenhao gdb Tutorial with GDB Debug program
    • The Art of Software debugging (electronic version)
5. Make and Makefilelinux C language Programming Fundamentals 1. Practice Vimtutuor at least once;

2. Use Vim to enter the following code, contact use "K" to find the Help document: 3. Practice GCC compile and run code;

4. Practice gdb debug Code; 5. Create a static library math.a and a shared library math.so;6 the code above in addition to the main function. Write the makefile, let the code compile, the use of the static library and the shared library is automated.

  

Linux under C Programming basics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.