Guide
Guide
WINDOWS
1. Install GCC toolchain
a. Go to this link: MinGW-W64-builds. Download x86_64 release-posix-seh-ucrt-rt with
latest version.
o After you download the file, right click on it and select “Extract Here” with WinRAR or
7-Zip tool to extract it. You will get the extracted folder mingw64 as below:
c. Copy the path of the bin folder. With the instructions above, the path will be
“C:\mingw64\bin” (it is fine if you copy it in another place with a different path but must
have no space characters in the path).
d. Add the above path to the Windows PATH environment variable so that gcc tool can
run without the full path in Windows Terminal (PowerShell and Command Prompt):
o In the search bar, search for “variables” and select “Edit the system environment
variables”.
o Select “Environment Variables”
o Under System variables area, select Path > Edit. In the Edit environment variable
window, press New and input path to the bin directory of our installed GCC tool. After
that, press OK in all windows to complete PATH setting.
d. Install and use Code Runner extension for “click to compile and run” feature.
o Search for "Code Runner" in the extension search box and install it.
• Click on File > Preferences > Setting. Search for Code Runner. Scroll down to find and tick on
option “Code-runner: Run In Terminal” (will make the program to run in terminal when we
hit Run button to compile the code).
• Now, you will see a RUN button which can be used to compile and run your program.
3. Get familiar with VS Code
a. Close and re-open VS Code if it is opening while or before doing the PATH setting above.
b. Click on File > Add Folder to Workspace. Browse to/ create a folder where you want to save all of
your programs (e.g. D:\MyCodingSpace), and select it.
c. Create a new file namelly hello.c with example program as below
d. Copy the following code and paste it into your hello.c file:
#include <stdio.h>
int main()
{
int num;
printf("Enter an integer: ");
scanf("%d", &num);
printf("Got number = %d", num);
return 0;
}
e. Compile and run it in the terminal
o Click on Teminal > New Terminal to open Windows’ Powershell terminal.
o In the terminal window, type “gcc hello.c” to compile the hello.c file. By default it will
generate a.exe in Windows as a result (can type “ls” to see all files). Then, type
“./a.exe” to run the program. It should work properly as below:
f. Alternatively, you can hit the RUN button of Code Runner to compile and run your program
MAC OS
1. Install VS Code and extensions
a. Go to https://code.visualstudio.com/download to download the suitable installer for your
Mac computer. Click on the downloaded file to install it.
b. Click on File > Auto Save to turn on Auto Save feature for all files (very helpful feature !).
c. Install C/C++ extension.
o Open VS Code. Click at the Extensions icon in the Activity Bar on the left side of VS
Code and search for "C/C++" in the Search box.
o Click on the Install button of the extension to install it
d. Install and use Code Runner extension for “click to compile and run” feature.
o Search for "Code Runner" in the extension search box and install it.
• Click on File > Preferences > Setting. Search for Code Runner. Scroll down to find and tick on
option “Code-runner: Run In Terminal” (will make the program to run in terminal when we
hit Run button to compile the code).
• Now, you will see a RUN button which can be used to compile and run your program.
2. Install GCC toolchain
a. Install homebrew
o Go to https://brew.sh/ and copy the installation script
o As shown above, the gcc version 11 has been installed. Check again by command
“gcc-11 –version”
Note: You may get another version depending on the current time of installation. For
example, if you got version 12, type gcc-12 --version.
c. Create a symbolic link (shortcut) file for gcc.
On Mac OS, the default compiler is clang. Thus, to use gcc, we need to create a symbolic
link namely gcc which links to our actual gcc-11 file (so that we can just type gcc to use
our actual gcc version 11 tool)
o Check where the gcc-11 is installed
which gcc-11
o Create a symbolic link file namely gcc g++ which links to our actual gcc-11
and g++-11 files as below
ln -s gcc-11 gcc
ln -s g++-11 g++
o Check again with “ls” command. You should see both files gcc, g++ (symbolic link)
and actual gcc-11, g++-11 file.
ls
d. Now, close and reopen the terminal, type “gcc --version” to check whether we have
successfully have configured it correctly or not. You should see it as Homebrew GCC (not
clang) as below:
Copy the following code and paste it into your hello.c file:
#include <stdio.h>
int main()
{
int num;
printf("Enter an integer: ");
scanf("%d", &num);
printf("Got number = %d", num);
return 0;
}
d. Click on Teminal > New Terminal to open Terminal.
e. In the terminal window, type “gcc hello.c” to compile the hello.c file. By default it will generate
a.out file as a result (can type “ls” to see all files). Then, type “./a.out” to run the program.
f. Alternatively, you can hit the RUN button of Code Runner to compile and run your program