0% found this document useful (0 votes)
12 views

1_EnvironmentBasics

This document outlines the steps to compile and run a C program using the terminal. It details how to write a C program in Gedit, compile it using the gcc command with appropriate flags, and execute the resulting output file. Additionally, it explains default naming conventions for output files based on the compilation options used.

Uploaded by

anurag.nair22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

1_EnvironmentBasics

This document outlines the steps to compile and run a C program using the terminal. It details how to write a C program in Gedit, compile it using the gcc command with appropriate flags, and execute the resulting output file. Additionally, it explains default naming conventions for output files based on the compilation options used.

Uploaded by

anurag.nair22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Steps to compile and run a C program

Open the terminal window with Ctrl+Alt+T

Launch the text editor Gedit.

Type your C program and save it with the extension .c

Compile it by typing the command:


gcc -Wall [name of your file].c -o [name of your output file].
In case of the current example,
gcc -Wall 1_hello.c -o hello

This compiles the source code in 'hello.c' to machine code and stores it in an executable file
'hello'.
The command line option -Wall turns on all the most commonly-used compiler warnings, it is
recommended that you always use this option.
You can check that the file hello is created by displaying the list of all the files and
subdirectories in the current directory in the terminal itself, using the ls command.

Run the output file by typing ./hello

If you compile with -c command line option (also called flag), and if you don’t use the -o flag, the
name of the output file is [name of your file].o by default. In the following function, the name of
the output files will be main.o and hello_function.o respectively.

If you specify neither -c nor -o then the output file will be a.out by default.

You might also like