Try to compile your code normally as

gcc test.c

If you get default output file a.exe,then go for

gcc test.c -o test.exe

Answer from Sathish on Stack Overflow
🌐
Wikihow
wikihow.com › computers and electronics › software › programming › c programming languages › how to compile a c program using the gnu compiler (gcc)
How to Compile a C Program Using the GNU Compiler (GCC)
February 19, 2026 - This wikiHow guide will teach you the easiest ways to compile a C program from source code using GCC. To make sure GCC is installed, run the command gcc --version. Type gcc source_file.c -o program_name and press Enter to compile your source code.
Discussions

gcc - How to compile C files in terminal - Raspberry Pi Stack Exchange
To compile from the command line (assuming yourcode.c is the name of your C file, and program the name of the resulting program after compilation): ... Or use your Leafpad editor (and make sure to know where your file is saved). Back to the terminal, navigate to where your C file is stored. (Reminder: ls to list directory contents, cd to change directory.) Compile your code with gcc ... More on raspberrypi.stackexchange.com
🌐 raspberrypi.stackexchange.com
Does gcc generate .o files to create the executable and then delete them or does it automatically create the executable from the source code file?
Compilation with gcc happens in multiple stages and not all of them are handled by gcc proper. The gcc compiler first takes the source C file and compiles it into an assembly file (.s extension). The assembly file is then translated into an object file (.o extension) by the GNU assembler (as or gas). Finally the object file(s) are linked into an executable by the linker (ld) which also takes care of libraries. All of this happens even if you just compile one source file directly into an executable, using temporary files. And yes, incremental compilation is exactly the reason to have intermediate object files. It's so you don't always have to recompile everything even if you just changed one source file. More on reddit.com
🌐 r/C_Programming
10
8
September 16, 2023
Quick Way to Compile C/C++ code in Vim
You'd use a Makefile, and the :make command in Vim. Once you've written the makefile you'd just do :make to compile everything you put in the makefile. More on reddit.com
🌐 r/vim
36
64
July 18, 2020
How to absolutely minimize the executable produced by GCC?
Surely you've found this? https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html More on reddit.com
🌐 r/C_Programming
35
48
August 1, 2022
🌐
Medium
medium.com › @laura.derohan › compiling-c-files-with-gcc-step-by-step-8e78318052
Compiling C files with gcc, step by step | by Laura Roudge | Medium
February 16, 2019 - We can stop the compilation process after this step by using the option “-c” with the gcc command, and pressing enter. Our main.o file should look like this (no, it’s not human readable): ... linking all the source files together, that is all the other object codes in the project.
🌐
iO Flood
ioflood.com › blog › gcc-linux-command
GCC Command Guide: How-To Compile C Code in Linux
December 12, 2023 - This command compiles the ‘filename.c’ file and outputs an executable named ‘outputfile’. ... In this example, we use the gcc command to compile the ‘hello.c’ file. The -o option is used to specify the name of the output file.
🌐
Stanford
web.stanford.edu › class › archive › cs › cs107 › cs107.1202 › resources › gcc
CS107 Compiling C Programs with GCC
Note that you do not put header files (.h) into the gcc command: it reads in the header files as it compiles, based on the #include statements inside .c files. If the program compiled without errors or warnings, you don't get any output from gcc, and you will have a new file in your directory, called a.out. To run this file, you need to tell the shell to run the file in the current directory, by using ./ before the name:
Top answer
1 of 3
16

Do NOT use nano (or another text editor to put your code into) with root/sudo permissions (ie. do not edit with sudo nano, only use nano) if all you are doing is personal stuff that does not need superuser permissions.

Answer

To compile from the command line (assuming yourcode.c is the name of your C file, and program the name of the resulting program after compilation):

  1. Write your code in your favorite editor:

    • In the terminal, type nano yourcode.c (assuming you want to use nano);
    • Or use your Leafpad editor (and make sure to know where your file is saved).
  2. Back to the terminal, navigate to where your C file is stored. (Reminder: ls to list directory contents, cd to change directory.)

  3. Compile your code with gcc -o program yourcode.c.

  4. Execute it with ./program. Done!

Bonus method

If you intend on compiling/executing your program quite a lot, you may save yourself time by writing a Makefile. Create this file with Leafpad (or, in terminal, nano Makefile), then write:

all:
    gcc -o program yourcode.c
    ./program

(Make sure you presently use Tab for indents, and not spaces.) Then every time you just type make in the terminal (or make all, but let’s keep things short!), your program will compile and execute.


Testing

Want to make sure your GCC installation works? Copy-paste the following to your terminal:

cd /tmp
cat <<EOF > main.c
#include <stdio.h>

int main() {
    printf("Hello World\n");
    return 0;
}
EOF
gcc -o hello main.c
./hello # Press Enter to execute your program

If it echoes “Hello World”, then you’re good to go.

2 of 3
4

Compiling C programs on the raspberry pi is rather simple. First, create your program in a text editor and save it as <insert name>.c It should be saved on the Desktop.

Next, open terminal. In it type:

cd Desktop

This changes the directory that the terminal is looking at to Desktop. This is also where our program is stored.

gcc -Wall <myName>.c -o <compiled name>

This is where the interesting stuff occurs. GCC is the compiler - it makes your code executable. -Wall activates compiler warnings - this is extremely helpful for debugging. The next line <myName>.c tells the computer where the code is stored. -o is an option - it tell GCC to compile. Lastly, <compiled name> is the name of your new program.

🌐
Medium
steffanynaranjo.medium.com › how-to-compile-c-files-with-gcc-step-by-step-5939ab8a6c47
How to compile C files with gcc, step by step. | by Steffany Naranjo Vargas | Medium
June 11, 2020 - The above command will generate helloworld.o as it is specified with -o option. And, the resulting file contains the machine instructions for the classic "Hello World!" program, with an undefined reference to printf. This is the final stage in compilation of “Hello World!” program.
Find elsewhere
🌐
Log2Base2
log2base2.com › C › basic › how-to-compile-the-c-program.html
How to compile c program in linux using gcc
2.vim file.c (file name can be anything but it should end with dot c extension) command. To Edit the file: 3.Press i to go to insert mode. Type your program. 4.To save the file: Press Esc button and then type :wq. It will save the file. To compile the program: Type, 5.gcc file.c ·
🌐
NTU
www3.ntu.edu.sg › home › ehchua › programming › cpp › gcc_make.html
GCC and Make - A Tutorial on how to compile, link and build C/C++ applications
In Unixes, we typically omit the .exe file extension (meant for Windows only), and simply name the output executable as hello (via command "gcc -o hello hello.c". You need to assign executable file mode via command "chmod a+x hello". You need to use g++ to compile C++ program, as follows.
🌐
Edureka
edureka.co › blog › how-to-compile-c-program-in-command-prompt
How to Compile & Run a C Program in Command Prompt?
July 23, 2024 - For instance, let’s consider a file named myprogram.c which needs to be compiled using gcc command as shown below: gcc myprogram.c -o myprogram.
🌐
EmbedJournal
embedjournal.com › compiling-c-programs-using-gcc
Compiling C Programs Using GCC - EmbedJournal
April 1, 2017 - And yeah, Linux doesn’t pop up ... is how to specify the output file name during compilation and execute it likewise, $ gcc filename.c -o executable.file $ ./executable.file...
🌐
Medium
medfouedjenni.medium.com › how-to-compile-a-c-program-using-gcc-b275c80cd572
How to compile a “C” program using GCC | by Mohamed Foued Jenni | Medium
September 18, 2020 - Note : you can type “man gcc” on your terminal for more information about the command. ... This will compile the “main.c” file and give the output file as “a.out” file which is default name of output file given by gcc compiler, which ...
🌐
Linuxtopia
linuxtopia.org › online_books › an_introduction_to_gcc › gccintro_9.html
An Introduction to GCC - Compiling a simple C program
The classic example program for the C language is Hello World. Here is the source code for our version of the program: · We will assume that the source code is stored in a file called 'hello.c'. To compile the file 'hello.c' with gcc, use the following command:
🌐
nixCraft
cyberciti.biz › nixcraft › howto › debian linux › how to compiling c program and creating executable file under a linux / unix / *bsd
How To Compiling C Program And Creating Executable File Under a Linux / UNIX / *BSD - nixCraft
December 11, 2017 - To compile C program first.c, and create an executable file called first, enter: $ gcc first.c -o first OR $ cc first.c -o first To execute program first, enter: $ ./first Output: ... However, both FreeBSD and Linux support direct make (GNU ...
🌐
LinkedIn
linkedin.com › pulse › compiling-c-files-gcc-step-john-jerry-daza-montero
Compiling C files with gcc, step by step
September 17, 2020 - To make our main.c code executable, we need to enter the command "gcc 4-puts.c", and the compilation process will go through the four steps it contains. Of course, gcc has options that allow us to stop the compilation process after each step.
🌐
Uu
docs.uppmax.uu.se › software › gcc_compile_c
Compile C using GCC - UPPMAX Documentation
Create and write a C source file called hello_world.c: ... No, as there is a system-installed GCC. For sake of doing reproducible research, always load a module of a specific version. If you need the C11 or C17 standards, use these module versions or newer: ... To compiles the file hello_world.c with run-time speed optimisation and creating an executable with a more sensible name, use:
🌐
Ruc
akira.ruc.dk › ~keld › teaching › CAN_e14 › Readings › How to Compile and Run a C Program on Ubuntu Linux.pdf pdf
1 How to Compile and Run a C Program on Ubuntu Linux Keld Helsgaun
gcc -o hello hello.c · This command will invoke the GNU C compiler to compile the file hello.c and output (-o) the result to an executable called hello.
🌐
Medium
salmenzouari.medium.com › how-to-compile-and-run-c-program-in-linux-using-gcc-b58ab78a5f53
How to Compile and Run C Program in Linux Using gcc? | by Salmen Zouari | Medium
September 18, 2019 - [root@host ~]# ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib64/crt1.o /usr/lib64/crti.o /usr/lib64/crtn.o helloworld.o /usr/lib/gcc/x86_64-redhat-linux/4.1.2/crtbegin.o -L /usr/lib/gcc/x86_64-redhat-linux/4.1.2/ -lgcc -lgcc_eh -lc -lgcc -lgcc_eh /usr/lib/gcc/x86_64-redhat-linux/4.1.2/crtend.o -o helloworld ... I executed the above command on an x86_64 system having gcc 4.1.2. It may be the above command does not work on your system as it is. It all matters that where the libraries located? For you, there is no need to type the complex ld command directly - the entire linking process is handled transparently by gcc when invoked, as follows. ... During the whole compilation process there are other files also in role along with the source code file.
🌐
GNU
gcc.gnu.org › onlinedocs › gcc › Invoking-GCC.html
Invoking GCC (Using the GNU Compiler Collection (GCC))
The usual way to run GCC is to run the executable called gcc, or machine-gcc when cross-compiling, or machine-gcc-version to run a specific version of GCC. When you compile C++ programs, you should invoke GCC as g++ instead. See Compiling C++ Programs, for information about the differences ...