Unix/linux System Programming

Source: Internet
Author: User

One, development tools

Compiler GCC

Debugging Tools GDB

Code Editor Vim

1. Compiling commands

gcc hello.c-o Hello  # Second Hello for the newly generated executable file name

-O Specify a name for the generated executable file.

-wall Print all warnings.

-E expands all user-defined predefined # define, generating the. I suffix of the C source file.

-C generates a binary file with the suffix name. O

-G generates executable binaries that can be debugged

2. Debug commands

L List of abbreviations, starting from the first line to list the code

Break 16 sets a breakpoint in line 16th of the code

Break Func sets a breakpoint at the entrance of the function func ()

Info Break View breakpoint Information

Shortcut to R run, run the program

N Next, execute the next statement

Shorthand for P i print I, printing variable i

C continue to run the program,continue command shorthand.

BT view the function stack.

Finish Exit Function

Q Exit GDB

Second, write makefile

Suppose there are three files prog.c, code.c, code.h, and the corresponding compilation commands are

gcc -C code.c-gcc -Cprog.c-gcc prog.o code.o-o test

But once you modify a file, you need to hand over the three commands again. With makefile, just a simple make command is all done.

Makefile Write as follows

TEST:PROG.O CODE.O         gcc prog.o code.o-o testprog.o:prog.c code.h        gcc -C prog.c-o prog.ocode.o:code.c Co De.h        gcc -C code.c-o code.oclean        :rm -F *.O Test

More advanced, you can also add macros to avoid "hard-coded" occurrences in makefile.

OBJS =gcc=-Wall Test: $ (BOJS)        -o test $ (CFLAGS) prog.o:prog.c code.h        -C prog.c-o prog.o $ (CFLAGS) code.o:code.c        code.h-C code.c-o code.o $ (CFLAGS)        clean: C11>rm -F *.O Test

Add:

[email protected] represents the current goal (target)

Makefile Rules

target:target file 1 target file 2 <tab>    gcc -o to create a new executable file destination file 1 target file 2

Unix/linux System Programming

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.