This article will briefly introduce how to build and use VIM + GCC + GDB for C Programming in Ubuntu.
I. Installation
Run sudo apt-Get install Vim on the command line and enter the administrator password as prompted.
Run sudo apt-Get install build-essential in the same way.
Build-essential is a C language development kit that includes tools such as gcc gdb.
Ii. Instances
1. Compile the source file
Open the command line and enter Vim. Enter I to enter the vim insertion mode. Write code.
# Include <stdio. h> <br/> int main () {<br/> printf ("Hello Linux"); <br/> return 0; <br/>}
After completion, Press ESC to return to normal mode, and enter W helloworld. C to save the source file as helloworld. C (note that the file name in Linux is case-sensitive)
2. Compile
Enter :! Gcc-wall-G helloworld. C-o helloworld
-Wall option: displays warning information.
-G option: Add debugging information to the target file.
-O option: Specify the target file name. If this parameter is not specified, A. Out is generated by default.
If the compilation is successful, the helloworld file will be generated in the directory where the source file is located. Press any key to return.
3. debugging
Enter :! GDB helloworld To Start program debugging.
The following lists some common gdb commands:
L <n> output source code from line N to line N + 9
Break <n> set a breakpoint on line N
Info break
R running
N single-step execution
C. Continue execution
P varname output variable value
Q exit