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)
2 weeks ago - Type gcc --version and press Enter to verify your installation. ... Go to the directory that contains your source code. Use the cd command to change to the directory in which you've saved the source code you want to compile.
Discussions

What is the correct way to compile c code
gcc main.c path/to/cfiles/*.c -I path/to/headers -o main Note that that is a capital i before path/to/headers not lowercase L If everything is in the same directory just do: gcc ./*.c -o main More on reddit.com
🌐 r/cprogramming
17
6
June 2, 2023
How to compile a c program by using gcc
I just find an errors the fist one is concerinig about the end of the line. To summit my Assignment which is the day after tommorow I have to compile my c program by using just gcc. If any one know what do I have to exclude or include in a code over the program that workes on visual c++? I ... More on community.unix.com
🌐 community.unix.com
0
April 4, 2006
gcc - How to compile C files in terminal - Raspberry Pi Stack Exchange
Question Can someone please tell me how to compile from the command line in a clear, concise way. Preferably, my programs will be written in a real text editor (such as leaf pad). Background I a... More on raspberrypi.stackexchange.com
🌐 raspberrypi.stackexchange.com
March 25, 2013
Does “C Programming: A Modern Approach” Show How To Compile?
Tutorial for compiling programs with GCC, everything you need to get started. More on reddit.com
🌐 r/C_Programming
13
5
June 28, 2020
🌐
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 - So once we compiled it, if we run this program we will only see the phrase “Hello, World” appearing. In order for our main.c code to be executable, we need to enter the command “gcc main.c”, and the compiling process will go through all of the four steps it contains.
🌐
Reddit
reddit.com › r/cprogramming › what is the correct way to compile c code
r/cprogramming on Reddit: What is the correct way to compile c code
June 2, 2023 -

I've got a program that is split into header files and c files along with the main. I was told to do gcc main.c <library.c>... for every other code but i don't remember having to do that when I've done stuff with header files in the past. How are you supposed to do this. Also are you supposed to include the headerfile in the .c version that the header is declaring the functions from? Sorry for my lack of technical terms. I'm exhausted today

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
🌐
Quora
quora.com › How-do-I-compile-a-C-program-using-a-GCC-compiler
How to compile a C program using a GCC compiler - Quora
Answer (1 of 4): Method 1 of 2:Using GCC for Linux 1. Open up a terminal window on your Linux system. Its icon usually is a black screen with some white characters on it. You can usually find it in your Applications menu. 2. Install GCC. If you do not have GCC already installed, you can use th...
Find elsewhere
🌐
GNU
gcc.gnu.org
GCC, the GNU Compiler Collection - GNU Project
The GNU Compiler Collection includes front ends for C, C++, Objective-C, Objective-C++, Fortran, Ada, Go, D, Modula-2, COBOL, Rust, and Algol 68 as well as libraries for these languages (libstdc++,...). GCC was originally written as the compiler for the GNU operating system.
🌐
Unix Community
community.unix.com › applications › programming
How to compile a c program by using gcc - Programming - Unix Linux Community
April 4, 2006 - Hi all, Yeasterday I try to compile c program by using cygwin. I just find an errors the fist one is concerinig about the end of the line. To summit my Assignment which is the day after tommorow I have to compile my c …
🌐
GeeksforGeeks
geeksforgeeks.org › c language › compiling-a-c-program-behind-the-scenes
Compiling a C Program: Behind the Scenes - GeeksforGeeks
Static Linking: All the code is copied to the single file and then executable file is created. Dynamic Linking: Only the names of the shared libraries is added to the code and then it is referred during the execution. GCC by default does dynamic linking, so printf() is dynamically linked in above program.
Published   July 23, 2025
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.

🌐
Stanford
web.stanford.edu › class › archive › cs › cs107 › cs107.1202 › resources › gcc
CS107 Compiling C Programs with GCC
This is just a quick overview on how to compile and run your own programs should you decide to do so without a Makefile. The simplest way to run gcc is to provide gcc a list of .c files:
🌐
Visual Studio Code
code.visualstudio.com › docs › cpp › config-mingw
Using GCC with MinGW
November 3, 2021 - Get the latest version of MinGW-w64 via MSYS2, which provides up-to-date native builds of GCC, MinGW-w64, and other helpful C++ tools and libraries. This will provide you with the necessary tools to compile your code, debug it, and configure it to work with IntelliSense.
🌐
Reddit
reddit.com › r/c_programming › new to c, can't compile anything.
r/C_Programming on Reddit: New to C, can't compile anything.
March 28, 2021 -

Im using VScode and whenever I try to run a program I get the error message:

"gcc : The term 'gcc' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."

I've tried troubleshooting and know you need something called MinGW or something but the website seems to be down so I'm not sure what to do. Any help is appreciated.

Sorry for being noob lol

🌐
Linuxtopia
linuxtopia.org › online_books › an_introduction_to_gcc › gccintro_8.html
An Introduction to GCC - Compiling a C program
This chapter describes how to compile C programs using gcc. Programs can be compiled from a single source file or from multiple source files, and may use system libraries and header files · Compilation refers to the process of converting a program from the textual source code, in a programming ...
🌐
LinkedIn
linkedin.com › pulse › demystifying-c-compilation-step-by-step-guide-gcc-nihad-gurbanov
Demystifying C Compilation: A Step-by-Step Guide with GCC
October 14, 2023 - Compiling C code is a fundamental step in software development. In this guide, we'll demystify the C compilation process using GCC, a popular C compiler.
🌐
Reddit
reddit.com › r/programmerhumor › gcc uses gcc to compile itself
r/ProgrammerHumor on Reddit: GCC uses GCC to compile itself
March 19, 2023 - So stage 0 is done with the system compiler with optimization and any fancy features turned off. That gives a functional but slow C compiler. Stage 1 uses the slow GCC to compile itself with all optimizations turned on, giving you a fast C compiler plus the rest of the suite that you pick C++, Ada, Fortran, etc.
🌐
openEuler
docs.openeuler.org › en › docs › 22.03_LTS_SP1 › docs › ApplicationDev › using-gcc-for-compilation.html
using-gcc-for-compilation | openEuler documentation | v22.03_LTS_SP1
The GNU Compiler Collection (GCC) is a powerful and high-performance multi-platform compiler developed by GNU. The GCC compiler can compile and link source programs, assemblers, and target programs of C and C++ into executable files.
🌐
EmbedJournal
embedjournal.com › compiling-c-programs-using-gcc
Compiling C Programs Using GCC - EmbedJournal
April 1, 2017 - It was released in the year 1987 and was the first component to be taken up by GNU. GCC is not just a compiler for C but it is a collection of compilers for a variety of languages such as, C, C++, Java and some more languages.
🌐
Quora
quora.com › How-did-people-compile-C-codes-before-the-invention-of-GCC
How did people compile C codes before the invention of GCC? - Quora
Answer (1 of 16): We used the many other C compilers that were available before GCC was released. GCC (originally called the GNU C Compiler, and now called the GNU Compiler Collection) was initially released in 1987, but it was far from the first C compiler available. Long before that, there we...