Gcc gdb make makefile

Source: Internet
Author: User

Http://www.cnblogs.com/4925278/archive/2012/11/28/gcc-gdb-make-makefile.html

Gcc-GDB-make-makefile

1. During GCC program compilation, the compilation and connection processes can be divided into four phases:

  Preprocessing(Pre-processing)

  Compile(Compiling)

  Assembly(Grouping)

  Connection(Linking)

2. GCC uses the file suffix to differentiate the type of the input file:

(1) Use. CFile with a suffix: C source code file.

(2).File with a suffix: it is a library file consisting of the target file.

(3). C,. CCOr. CxxFile with a suffix: C ++ source code file.

(4). HFile with a suffix: header file.

(5) Use. IFiles with suffixes: C source code files that have been preprocessed.

(6). IIFiles suffixed with: C ++ source code files that have been pre-processed.

(7) Use. OFile with a suffix: the target file that is not connected after compilation.

(8). SFiles suffixed with: source code files of the assembly language.

(9). SFiles with suffixes: Pre-compiled source code files of the assembly language.

3. GCC basic commands:

Command Format: GCC [Option][Filename]

Option value:

-O: Specify the target file name after compilation.

GCC hello. C-O hello --> hello

GCC hello. c --> A. Out

-C: Only compilation is not connected to an executable file.

-G: generate the necessary symbolic information for the debugging program (gnu gdb.

-O: optimizes compilation and connection of programs. Compilation and connection are slower.

-O2: optimized compilation, connection, and program compilation and connection are slower than-o.

-Idirname: add the directory specified by dirname to the program header file directory list (/usr/include.

-Ldirname: add the directory specified by dirname to the library file directory list (/usr/lib.

-Lname: load the function library named "libname. A" during connection.

-Static: static Connection Library file.

-Wall: generates all warning information.

-W: no warning information is generated.

-Dmacro: defines the macro, which is equivalent to using # define macro in a program.

4. GDB debugging program

(1) functions:

A. Start the program to be debugged.

B. Stop the program to a specified position.

C. Check the program status when the program is stopped.

(2) related commands

Life order Meaning

GDB

GDB filename

Start GDB
L/List Show source program (L + row number shows row N)
B/break function name Add a breakpoint at the entrance of a function
B/break row number Add a breakpoint to a specified row
B/break file name: row number Add a breakpoint to the specified row of the specified file
B/break row number if condition When the condition is true, the breakpoint of the specified row takes effect.
Info break View All set breakpoints
Delete breakpoint number Deletes a specified breakpoint.
R/run Start running the program
N/next Run the program in one step (do not enter the sub-function)
S/step Run the program in one step (enter the sub-function)
C/continue Continue running the program
P/print variable name View the value of a specified variable
Finish Run the program until the current function ends.
Watch variable name Monitor specified variables
Q/quit Exit GDB

 

      

 

 

 

 

 

 

 

 

 

 

 

 

5. Make and makefile

(1) in Linux, use make to build and manage your own software projects. GNU make can compile and link the entire software project with only one command.

(2) During the execution of make, a file named makefile is required. The MAKEFILE file describes the compilation and connection rules of the entire project.

(3) Write makefile:

A. Rule: describes how to generate one or more target files. The rule format is:

Targets: prerequisites

Command

Target: dependency

Command

The command must start with the tab key.

B. By default, the make command searches for the project file named makefile or makefile in the current directory. If the name is not the same, you can use the following method to specify the file: Make-F file name.

C. pseudocommands: There is no dependency and only the target of the execution action.

Example:. Phony: clean

Clean:

Rm-F Hello main. O func1.o func2.o

". Phony" declares the "clean" target as a pseudo target.

D. Variables

Basic usage: OBJ = Main. O func1.o func2.o

Hello: $ (OBJ)

GCC $ (OBJ)-O hello

The default automation variable exists in makefile:

$ ^: Indicates all dependent files.

$ @: Indicates the target

$ <: Represents every dependent File

The content after the "#" character in makefile is considered as a comment.

In makefile, "@ + command" can cancel the echo of a command during execution.

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.