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
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
I would suggest you go through this compilation instruction :-
gcc -o test.exe test.c
I believe this code runs perfectly on your windows system.Please inform if it doesn't!
gcc - How to compile C files in terminal - Raspberry Pi Stack Exchange
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?
Quick Way to Compile C/C++ code in Vim
How to absolutely minimize the executable produced by GCC?
Videos
Do NOT use
nano(or another text editor to put your code into) with root/sudo permissions (ie. do not edit withsudo nano, only usenano) 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):
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).
- In the terminal, type
Back to the terminal, navigate to where your C file is stored. (Reminder:
lsto list directory contents,cdto change directory.)Compile your code with
gcc -o program yourcode.c.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.
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.