Install gcc and run code on Linux (Ubuntu as an example)

Table of contents

1. Install gcc

2. Compile and run the code with gcc


 First check network connectivity

1. Install gcc

1. Open the virtual machine terminal and install gcc

Enter: sudo apt install gcc

 2. Check after installation is complete

Input: gcc -version

If the following content appears, the installation is successful: 

If the following content appears, the installation was not successful and needs to be reinstalled.

2. Compile and run the code with gcc

1. First create a file named test.c in the terminal and enter ls to view it.

 2. Enter vim test.c to edit the file code.

#include <stdio.h>
int mian()
{
    printf("Hello World!\n");
    return 0;
}

3. To exit editing enter “:wq”.

:wq

4. Compile the file and check it with ls after completion. If there is more a.out file, the compilation is successful.

 5. Execute the a.out file. The output result is Hello World as shown below.


Guess you like

Origin blog.csdn.net/qq_46017623/article/details/131390130