How to Compile and Run C program Using GCC on Ubuntu 22.04 LTS / Ubuntu 24.04 LTS (Linux)

ProgrammingKnowledge2
ProgrammingKnowledge2
12 هزار بار بازدید - پارسال - In this video I am
In this video I am going to show How to Compile and Run C program Using GCC on Ubuntu 22.04 LTS Linux. Same instruction will be valid for Linux mint, Debian and other Linux systems
==========================================
Confirm your installation by checking for GCC version by the command:
gcc --version
===========================================
Install build-essential by the command:
sudo apt install build-essential
===========================================
To compile the code within hello.c file, compile and execute it:
$ gcc -o hello hello.c
$ ./hello
Hello, World!
===========================================
To compile and run a C program using GCC on Ubuntu, follow these steps:

1. Open Terminal: Launch the Terminal application on your Ubuntu system. You can do this by searching for "Terminal" in the application launcher or by using the keyboard shortcut Ctrl+Alt+T.

2. Navigate to the C Program Directory: Use the `cd` command to navigate to the directory where your C program is located. For example, if your program is in the "Documents" folder, you can use the following command:
```
cd ~/Documents
```
Replace "~/Documents" with the actual path to your program directory.

3. Write Your C Program: Use a text editor (such as Nano, Vim, or VSCode) to create or open your C program file. Write your C code in the text editor and save the file with a .c extension. For example, you can save your program as "myprogram.c".

4. Compile the C Program: In the Terminal, use the following command to compile your C program using GCC:
```
gcc -o outputfilename inputfilename.c
```
Replace "outputfilename" with the desired name for the compiled output file (e.g., "myprogram") and "inputfilename" with the name of your C program file (e.g., "myprogram.c").

5. Verify Successful Compilation: If there are no errors in your C program, the compilation process will complete without any output. However, if there are errors, you will see error messages in the Terminal, indicating the issues that need to be fixed.

6. Run the Compiled Program: After successful compilation, use the following command to run your compiled C program:
```
./outputfilename
```
Replace "outputfilename" with the name you specified during compilation (e.g., "myprogram").

7. View Program Output: The output of your C program will be displayed in the Terminal. If your program requires any user input, provide the input in the Terminal as required.

By following these steps, you can compile and run a C program using GCC on Ubuntu. This allows you to execute your C code and observe the program's output or any errors that may occur during execution.

#Ubuntu #CProgramming #GCC #Terminal #CompileCProgram #RunCProgram #CProgramCompilation #Linux #Programming #SoftwareDevelopment #CodeExecution
پارسال در تاریخ 1402/04/19 منتشر شده است.
12,077 بـار بازدید شده
... بیشتر