Visual Studio Code and GCC - Installation Guide PDF
Visual Studio Code and GCC - Installation Guide PDF
Windows
1. Install VS Code
• Download the VS Code installer for Windows
• Double-click at the downloaded file to run the installer
- Now, open the extracted folder, you will see a folder namely mingw64 inside. Select
and copy that folder to your C drive. You will see it as below.
b. Browse to bin folder then copy its path. With instructions above, the path will
be “C:\mingw64\bin” (it is fine if you copy it in another place and have
different path but must have no space characters in the path).
c. Add the above path to the Windows PATH environment variable so that gcc can
run without the full path in Windows Terminal (PowerShell and Command Prompt):
o In search bar, search for “variables” and select “Edit the system 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.
c. Click on File > Auto Save to turn on Auto Save feature for all files (very helpful feature !).
e. 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:
6. Install and use Code Runner extension for “click to compile and run” feature.
• Click at the Extensions icon in the Activity Bar on the left side of VS Code
Type "Code Runner" in the Search box to search for it, and click at the Install button of
the extension.
• Go to 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).
• Now, you can hit the RUN button to compile and run your program.
Mac OS
1. Install VS Code
• Download the VSCode to a directory
• Open Finder and navigate to that directory
• Double-click at the zip file to unzip it
• Drag the Visual Studio Code.app to the Applications directory to make it
available in Launchpad
Note: If you use macOS Catalina (macOS 10.15), you may see a message "Visual Studio Code
can't be opened because Apple cannot check it for malicious software". This is because
Visual Studio Code is not currently notarized but it will run just fine on macOS Catalina. To work
around the notarization check, open Launchpad > System Preferences
> Security & Privacy > General and choose Open Anyway.
Note: You may get another version depending on the current time of installation. For example, if
you got version 12, type gcc-12 –version.
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)
You may get /usr/local/bin/gcc-11 as the result, then it is in /usr/local/bin/ (some people may get
another location, e.g. /opt/local/bin/gcc-11).
- cd to the location that you get above and list out content by flowing commands.
You should see gcc-11 file there:
cd /usr/local/bin
ls
Note: in “ls” and “ln” commands, l is L letter in lower-case (not i letter).
- Create a symbolic link file namely gcc which links to our actual gcc-11 file as below
ln -s gcc-11 gcc
- Check again with “ls” command. You should see both files gcc (symbolic link) and actual gcc-11
file.
ls
d. Now, close and reopen the terminal, type “gcc –version” to check that whether we have
successfully have configured it correctly or not. You should see it as Homebrew GCC (not
clang) as below:
4. Install GNU Make tool
a. Check that you already have the make tool or not
make --version
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 File > Auto Save to turn on Auto Save feature for all files (very helpful feature !).
f. 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.
6. Install and use Code Runner extension for “click to compile and run” feature.
a. Click at the Extensions icon in the Activity Bar on the left side of VS Code
Type "Code Runner" in the Search box to search for it, and click at the Install button of
the extension.
b. Go to Code > 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).
c. Now, you can hit the RUN button to compile and run your program.
Linux (Ubuntu/Debian/Mint)
Similarly for Linux:
1. Install VS Code
Download the deb file to a directory
Open Terminal then navigate to that directory
$ sudo apt install ./<file>.deb
Note: <file>.deb must be replaced by the exact name of the downloaded deb file.