Summary of common usage of programming tools in Linux

Source: Internet
Author: User

This evening, I got familiar with the programming tools in Linux, including VI, emacs, GCC, GDB, makefile, and autotools. Initial involvement
In Linux, none of the above tools can be fully sophisticated at half past one, but often each tool has some commands that can be used as frequently as 70%. Exercise for one night and make a summary of common usage.
Fixed memory.

I. VI: common source code editing commands.

VI hello. C: Generate hello. C in the current directory and enter the command mode

In command mode
You can delete, copy, and paste files.

1) press I, A, or O to enter the insert mode. You can type characters. Generally, I; A is slightly different from O.

2) Key DD: Delete the row where the cursor is located

3) number (n) + dd Delete cursor start down n rows

4) number (n) + YY copy the cursor to start n rows down

5) P paste to the cursor

6) U undo the last operation

In insert mode, Press ESC to enter the baseline mode, mainly for operations such as disk storage and exit

1): WQ is the most commonly used. Save and exit

2): W [filename] is saved or saved separately.

3): Q! Strong exit vi

Ii. Common GCC usage:

1) GCC-e hello. C-O hello. I // preprocessing

2) GCC-s hello. I-O hello. S // compile it into an assembly language file

3) GCC-C hello. S-O hello. O // compile it into the target code

4) GCC-C hello. C-O hello. O // directly generate the target code file <most common>

5) GCC hello. C-O hello // directly generate an executable file

6) GCC hello1.o hello2.o-O hello // link to generate executable files <most common>

Common options
:

1)-G generates GDB debugging information. This item is required by the gdb tool.

2)-the header files in the specified directory are included in the I dir compilation process.

3)-l dir may need to link the library file to the Dir

4)-llibrary links to the dynamic libaray library. Generally, the first three letters (LIB) without the library name are not included. For example,-lhello indicates the link libhello. So dynamic library.

5)-static Link Static Library

6)-wall allows all useful warnings

7)-O (-O2 or-O3) for code optimization (level 3), generally not in the debugging phase

Common usage of GDB debugging

Start debugging with GDB hello. The-G option must be included during compilation.

Common Operations:

1) L (list) view source code

2) B (breakpoint) N: Set a breakpoint on line N.

3) R (run) Run

4) n (next) is executed in a single step and does not enter the function, which is equivalent

5) S (STEP): Execute in one step and enter the function, which is equivalent to F11.

6) C (contiue) continues to run from the current running point to the next breakpoint or program end.

7) P var: view the current value of the variable VAR

8) finish running till the end of the program

Useful commands related to breakpoints
:

1) view information about all configured breakpoints in info B

2) B function sets a breakpoint in the row where the function is located.

3) when the number of B rows or function name if expression meets the expression, the operation is interrupted <feeling more important>

4) Delete [breakpoint number] Delete

5) Disable [breakpoint number] Disabled

6) enable [breakpoint number] Activation

If the breakpoint number is not included, the command takes effect on all the breakpoint numbers. The breakpoint number can be obtained using info B.

7) Ignore [breakpoint number] n ignores the breakpoint n times, which is useful for loop programs.

View useful commands for variables during running
:

Print expression or variable

Display expression. I have heard that the corresponding expression content is automatically displayed (not tried)

Variable modification command
:

Set Var = value to set the variable value.

4. Write makefile

It is used to automatically compile and generate the target or executable file to facilitate maintenance of software engineering upgrade and modification.

Basic Format
:

Target: dependency_files

Command

For example:

Hello. O: Hello. c hello. h

Gcc-C hello. C-O hello. o

Makefile variable
:

For example:

Objs = hello1.o hello2.o

Cflags =-wall-o-g

Cc = gcc

Hello: $ (objs)

$ (CC) $ (objs)-O hello

Hello1.o: hello1.h hello1.c

$ (CC) $ (cflags)-C hello1.c-O hello1.o

Hello2.o: hello2.h hello2.c

$ (CC) $ (cflags)-C hello2.c-O hello2.o

You can also use its implicit rules.
, Then hello1.o and hello2.o do not need to be output. The following rules are automatically applied to the generation of each *. O target code:

*. O: *. C *. h

$ (CC) $ (cflags)-C *. C-o *. o

Automatic Variable usage

$ ^: Indicates that all dependent files are not repeated.

$ <: The first dependent File

$ @: Full name of the target file

Usage rules

%. O: %. c

$ (CC) $ (cflags)-C $ <-o $ @

Make command:

Make target name generation target

Make generates the first target.

5. Use autotools:

Generate makefile automatically

1) Run autoscan DIR or run autoscan in the current directory. Generate Configure. Scan

2) EDIT Configure. Scan to add macro: am_init_automake (executable file name, version number)

Change the name to configure. In.

3) Run aclocal to obtain aclocal. M4.

4) Run Autoconf to generate the configure Executable File

5) Run autoheader to generate the config. H. In File // this step is not important.

6) Create and edit the makefile. Am file:

Automake_options = foreign

Bin_programs = Hello (this is an executable file)

Hello_sources = Hello. c hello. H (dependent file here)

Save

7) Run automake to generate makefile. am.

8) run the configure executable file to generate makefile. In.

9) run make to generate hello

The flowchart of the online search is as follows:


 
Main functions of makefile generated by autotools
:

1. Make [all] To generate an executable file

2. Make install to generate an executable file and install it in the system directory, for example,/usr/local/bin.

3 make clean: Clear All executable files and target files generated by the previous compilation *. o

4 make Dist package programs and documents for release

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.