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

Installation and use of vim+gcc+gdb under Ubuntu

2025-03-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Installing GCC under Ubuntu is a little different from some other Linux systems.

I) installation

Vim) Open the command line and run sudo apt-get install vim, and enter the administrator password as prompted.

Gcc+gdb) enter the command line to run sudo apt-get install build-essential

Build-essential, which includes tools such as gcc and gdb, is a C language development kit.

After installation, you can execute

Gcc--version

To view the version, the output is as follows:

Gcc (GCC) 4.2.3 (Ubuntu4.2.3-2ubuntu7)

Copyright (C) 2007 FreeSoftware Foundation.

The gcc command is used for compilation. To learn further, you must first be familiar with the use of the gcc command.

Gcc command provides a lot of command options, but not all of them should be familiar with, just master a few commonly used options, and then slowly learn other options later, so as not to undermine the confidence of learning because of too many options.

II) Common compilation command options

Suppose the source program file name is test.c.

1. No option compilation link

Usage: # gcc test.c

Function: preprocess, assemble, compile and link test.c to form an executable file. No output file is specified here, and the default output is a.out.

two。 Option-o

Usage: # gcc test.c-o test

Function: preprocess, assemble, compile and link the test.c to form an executable file test. The-o option specifies the file name of the output file.

3. Option-E

Usage: # gcc-E test.c-o test.i

Function: test.c pre-processing output test.i file.

4. Option-S

Usage: # gcc-S test.i

Function: assemble the preprocessed output file test.i into a test.s file.

5. Option-c

Usage: # gcc-c test.s

Function: compile the assembly output file test.s to compile the output test.o file.

6. No option link

Usage: # gcc test.o-o test

Function: link the compiled output file test.o into the final executable file test.

7. Option-O

Usage: # gcc-O1 test.c-o test

Purpose: use compiler optimization level 1 to compile the program. The level is 1-3, the higher the level, the better the optimization, but the longer the compilation time.

III) the compilation method of multi-source files

If you have multiple source files, there are basically two compilation methods:

[suppose two source files are test.c and testfun.c]

1. Multiple files compiled together

Usage: # gcc testfun.c test.c-o test

Function: testfun.c and test.c are compiled and linked into test executable files respectively.

two。 Compile each source file separately, and then link the compiled output target file.

Usage:

# gcc-c testfun.c / / compile testfun.c to testfun.o

# gcc-c test.c / / compile test.c to test.o

# gcc-o testfun.o test.o-o test / / Link testfun.o and test.o into test

IV) use of the gdb debugger

Enter the command: gdb Cfilename to start debugging the program.

Here are some common gdb commands:

L output the source code from line n to line 9

Break sets a breakpoint on line n

Info break view breakpoint information

R operation

N single step execution

C continue to execute

P varName output variable value

Q exit

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

Internet Technology

Wechat

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

12
Report