This is my personal school stuff, compiled with gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0.
RIP conio.h
, you were a real one... Not.
Steps to compile a C program.
In case you need help setting up, click here.
Just make
, bro. :)
make
The command nproc
tells you how many thread you have on your computer.
nproc
Running make -j will speed up the process, based on the number of threads on your computer.
make -j${nproc}
make
will build all source files present in /src
.
To run any program, in this case let's assume it's hello.c
./build/hello
In case you want to erase all build artifacts,
make clean
make clean
will erase all build artifacts, allowing you to make
again.
If you're compiling and running on Turbo C++, please don't forget to do the following steps.
#include <stdio.h>
+ #include <conio.h>
void main()
{
int a, b, c;
+ clrscr();
...
...
+ getch();
}
You need to include conio.h
, and use the functions clrscr()
before printing statements, and getch()
at the bottom.
-
Compiling.
- Let's assume you're compiling hello.c,
gcc hello.c -o hello.o
- In other places, replace
hello.c
andhello.o
with the appropriate file name. - By default, running this command won't create the output file in
build
dir, it'll be in thesrc
dir, unless youmake
or use a more complex command.
-
Running.
- Again, assuming you're running hello.c
./hello.o
- Again, assuming you're running hello.c
And that's it. Enjoy :)
In case you need help setting up your environment.
- Stepwise Guide to Enable Windows Subsystem for Linux (WSL)
- Compile C program with gcc compiler on Bash on Ubuntu on Windows 10 & 11
- Turbo C++
All people who helped in one way or the other.
- anyone who wrote these programs (me, and everyone who contributed).
- ChatGPT for writing the Makefile (yes I got desperate).
- my C lecturer.
- Vineet Choudhary.