Since GCC is intended for Unix based systems, you will need to install a 3rd party port of GCC to have C programs successfully compile on Windows. The recommended compiler for C development is MinGW-w64.
You can find the link to the installer here:
Take note of where you install the files. By default they should be in C:\Program Files\mingw-w64
Assuming that you already have VS Code and MinGW-w64 installed, add the path to your Mingw-w64 bin
folder to the Windows PATH environment variable.
Path
variable and then select Edit.C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin
.Path
update. You will need to reopen any console windows for the new PATH location to be available.g++ --version
gdb --version
helloworld.c
#include <stdio.h>
int main()
{
printf("Hello World");
};
Save it in a folder that will become the workspace.
Open VS Code and navigate to Terminal > Configure Default Build Task
While typing, you should see a drop down for C/C++:gcc.exe build active file
. Select that. This will open a new tasks.json file.
helloworld.c
and navigate to Terminal > Run Build Task or typeCtrl-Shift-B
. This will run the compiler and create an executable.
dir
to see all files in the workspace../helloworld.exe
.helloworld.c
file.