You don't need a code runner. You can configure VSCode to allow you to run the code and also debug it in a much better way.

Check for GCC

Go to the terminal and type gcc --version into it.

If you get something like this:

Copygcc (Rev1, Built by MSYS2 project) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

It means GCC is installed and should be found by VSCode.

tasks.json

You'd have to give the correct paths to tasks.json to perform the builds and runs. Here's an example

{
    "version": "2.0.0",
    "tasks"  : 
    [
        {
            "label"  : "build release",
            "type"   : "shell",
            "command": "gcc main.c -O2 -o ${workspaceFolderBasename}.exe"
        },
        {
            "label"  : "build debug",
            "type"   : "shell",
            "command": "gcc main.c -g3 -o ${workspaceFolderBasename}.exe"
        },
        {
            "label"  : "run_executable",
            "type"   : "shell",
            "command": "./${workspaceFolderBasename}.exe"
        }
    ]
}

This assumes that the executable name you want is the same as your folder name. For example if the folder name is my_c_project then the executable would become my_c_project.exe. You can of course give custom names by replacing ${workspaceFolderBasename}.

To run it or debug it, you'd need GDB. To check for it, use gdb --version in a terminal and it should give you this output.

CopyGNU gdb (GDB) 13.2
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

And also you'd have to configure the launch configuration.

launch.json

Here's an example

{
    "configurations": [
    {
        "name"           : "Debug Config",
        "type"           : "cppdbg",
        "request"        : "launch",
        "program"        : "${workspaceRoot}/${workspaceFolderBasename}.exe",
        "args"           : [],
        "preLaunchTask"  : "build debug",
        "stopAtEntry"    : true,
        "cwd"            : "${workspaceRoot}",
        "environment"    : [],
        "externalConsole": false,
        "MIMode"         : "gdb",
    }
    ]
}

The first important bit in it is the program parameter which should point to the program created after building. You can see that the build debug and build release tasks both create the executable at the base folder, (the same place where your main.c is placed). And so the program property of launch.json is also pointing to the same executable.

And the second important bit is the preLaunchTask parameter which tells the debugger to perform a task before it starts debugging. It's been set to the build debug task, so every time you debug, it will rebuild to let you use the latest code.

Once you've set these up, just go to the debug tab and click on the green debug symbol on the top right.

And it would start debugging. Viola!

Answer from Usman Mehmood on Stack Overflow
🌐
Visual Studio Code
code.visualstudio.com › docs › cpp › config-mingw
Using GCC with MinGW
November 3, 2021 - Install the C/C++ extension for VS Code. You can install the C/C++ extension by searching for 'C++' in the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)). Get the latest version of MinGW-w64 via MSYS2, which provides up-to-date native ...
🌐
DEV Community
dev.to › mohosin2126 › setting-up-cc-development-environment-in-visual-studio-code-using-mingw-25og
Setting Up C/C++ Development Environment in Visual Studio Code Using MinGW - DEV Community
December 20, 2024 - Install Essential Extensions Open VS Code and install these extensions from the marketplace (you can find them by pressing Ctrl+Shift+X): C/C++ (Official Microsoft extension for C and C++) ... Go to File > Preferences > Settings.
🌐
Reddit
reddit.com › r/vscode › install mingw-w64 in vscode
r/vscode on Reddit: Install mingw-w64 in VScode
April 14, 2018 -

Newbie, windows_NT x64 10.0.17763, vscode 1.40.2, trying to learn C++

After install of vscode I noted at C/C++ Edit Configurations / Compiler path field says (No compiler paths detected).

Learned form vscode website I need to install one. Downloaded mingw-w64 v7. Instruction on various youtube videos say to copy the path from the 'bin' directory within the mingw-w64 folder and paste this into the compiler path field in the compiler path field but there is no such directory called 'bin' in the mingw-w64 folder. Anyone know what I should use as the path for this?

Screen clip of c/c++ compiler config path

From mingw_w64 folder, searched for *bin* (recusively). No directory hits.
Top answer
1 of 1
3

You don't need a code runner. You can configure VSCode to allow you to run the code and also debug it in a much better way.

Check for GCC

Go to the terminal and type gcc --version into it.

If you get something like this:

Copygcc (Rev1, Built by MSYS2 project) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

It means GCC is installed and should be found by VSCode.

tasks.json

You'd have to give the correct paths to tasks.json to perform the builds and runs. Here's an example

{
    "version": "2.0.0",
    "tasks"  : 
    [
        {
            "label"  : "build release",
            "type"   : "shell",
            "command": "gcc main.c -O2 -o ${workspaceFolderBasename}.exe"
        },
        {
            "label"  : "build debug",
            "type"   : "shell",
            "command": "gcc main.c -g3 -o ${workspaceFolderBasename}.exe"
        },
        {
            "label"  : "run_executable",
            "type"   : "shell",
            "command": "./${workspaceFolderBasename}.exe"
        }
    ]
}

This assumes that the executable name you want is the same as your folder name. For example if the folder name is my_c_project then the executable would become my_c_project.exe. You can of course give custom names by replacing ${workspaceFolderBasename}.

To run it or debug it, you'd need GDB. To check for it, use gdb --version in a terminal and it should give you this output.

CopyGNU gdb (GDB) 13.2
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

And also you'd have to configure the launch configuration.

launch.json

Here's an example

{
    "configurations": [
    {
        "name"           : "Debug Config",
        "type"           : "cppdbg",
        "request"        : "launch",
        "program"        : "${workspaceRoot}/${workspaceFolderBasename}.exe",
        "args"           : [],
        "preLaunchTask"  : "build debug",
        "stopAtEntry"    : true,
        "cwd"            : "${workspaceRoot}",
        "environment"    : [],
        "externalConsole": false,
        "MIMode"         : "gdb",
    }
    ]
}

The first important bit in it is the program parameter which should point to the program created after building. You can see that the build debug and build release tasks both create the executable at the base folder, (the same place where your main.c is placed). And so the program property of launch.json is also pointing to the same executable.

And the second important bit is the preLaunchTask parameter which tells the debugger to perform a task before it starts debugging. It's been set to the build debug task, so every time you debug, it will rebuild to let you use the latest code.

Once you've set these up, just go to the debug tab and click on the green debug symbol on the top right.

And it would start debugging. Viola!

🌐
Medium
medium.com › @abhinavsinha_ › setting-up-visual-studio-code-for-c-c-on-windows-d02ede716280
Setting up Visual Studio Code for C/C++ on Windows | by Abhinav Sinha | Medium
September 14, 2021 - As we have set up our compiler, now we’re all ready to download VSCode and write our first C/C++ program. Click here to download VS Code. After downloading open the setup file. Accept the agreement, check all the boxes shown in the picture, ...
🌐
YouTube
youtube.com › watch
How to install Visual studio Code and how to configure MinGW compiler on it for C - YouTube
In this video I've explained you about how to install MinGW Compiler on VS Code and how to configure it to run C and C++ program.#compiler #vscode #mingw
Published   August 28, 2023
🌐
CodeWithHarry
codewithharry.com › blogpost › setup-cpp-for-vs-code
How to Install & Setup VS Code for running C++ Programs | Blog | CodeWithHarry
Go to This PC → C:/ → Program Files (x86) → mingw-w64 → i686-8.1.0-posix-dwarf-rt_v6-rev0 → mingw32 → bin. Step 6: Copy the path and paste it in the environment variables. Right-click on This PC → Properties → Advanced System Settings → Environment variables. Step 7: Click on the path and then Edit → New. Paste the copied path here and click 'ok.' Step 8: Now, open VS Code and download the C/C++ extensions as shown in the below animation: Step 9: To run the C++ programs easily on VS Code, you need to install another extension called “Code Runner.”
🌐
YouTube
youtube.com › kerim academy
Setup C++ in VS Code | Install MinGW Compiler & VSCode and run C++ Programs - YouTube
How to set up C++ with Visual Studio Code (vscode).Install Visual Studio Code: https://code.visualstudio.com/Install minGW (C++ Compiler): https://code.visua...
Published   February 7, 2024
Views   613
🌐
YouTube
youtube.com › watch
Lec 1: How to Install and Set Visual Studio Code and MinGW Compiler for C and C++ | C++ Tutorials - YouTube
🔥 Jenny's Lectures Mastering DSA with Java course(New Batch): https://www.jennyslectures.com/courses/Mastering-DSA-with-JAVA-2-68ce8b083425e77d71739441⚡ Lim
Published   May 2, 2022
Find elsewhere
🌐
YouTube
youtube.com › watch
Installing MinGW Compiler for VSCode on Win 10 x64
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
🌐
YouTube
youtube.com › watch
Installing MinGW to build C++ Code on Windows - YouTube
In this video, we guide you through installing the MinGW toolkit to compile C++ on a Windows machine in Visual Studio Code.*0:00 Introduction0:14 MinGW Expla...
Published   January 5, 2024
🌐
GitHub
gist.github.com › Adrian-LL › 3a7d676bacbcfdd9671d484cc86c5f76
Using Visual Studio Code for C++ (Part 1 - Windows, MSYS / MinGW) · GitHub
Modify the PATH system variable in Windows (through "Edit the system variables" in Control Panel - you can edit it system-wide or per-user) to contain the paths for MSYS and MinGW installations. Launch cmd.exe and verify the paths by running gcc -V and g++ -V (you can try also gbd, make, cmake, etc.) If you din not already installed you can do it now. ... NOTE - You may get an error about git, let's ignore it for the moment. IMPORTANT - Install C/C++ (Microsoft) extension (latest version was 0.20.1). This can be triggered by VSC if you enter a small code such as below and saving the file with a .cpp extension:
🌐
Visual Studio Code
code.visualstudio.com › docs › languages › cpp
C/C++ for Visual Studio Code
November 3, 2021 - Download using this direct link to the MinGW installer. Run the installer and follow the steps of the installation wizard. Note, MSYS2 requires 64 bit Windows 8.1 or newer. In the wizard, choose your desired Installation Folder.
🌐
Reddit
reddit.com › r/c_programming › can anyone help me to setup vs code and mingw for c language.i tried from yt but it worked only one time
r/C_Programming on Reddit: Can anyone help me to setup vs code and mingw for c language.I tried from yt but it worked only one time
December 1, 2024 - In case you wanna stay strictly in windows (no extra advantage but you may have your reasons), go for vs community. Installs easy, works out of the box but you will have to spend like half a day understanding solutions, projects. I'll prefer WSL + Ubuntu. If you fuck up (not so easy), just discard it and install new instance of WSL. ... Dont use VScode. That's it. Use a real IDE. Like VS for windows things or Eclipse/CodeBlocks otherwise ... Here's how to setup MinGW on Windows: https://www.youtube.com/watch?v=k6juv3mIr9o And here's how to integrate it with VSCode on Windows: https://www.youtube.com/watch?v=4mvf73HvcVI
🌐
Southern
cs.southern.edu › halterman › Courses › Winter2018 › 124 › Labs › vscode-setup-windows.html
Setting Up Visual Studio Code
Install the MinGW C++ tools. Download the file MinGW-124.zip. In a Windows Explorer window, right click on the file and select "Extract All ..." In the ensuing dialog box be sure to type C:\ in the text field that specifies the folder into which the files will be extracted.
🌐
Stack Overflow
stackoverflow.com › questions › 72870788 › solved-installing-mingw-for-vscode-on-windows-10
c++ - (Solved) installing mingw for vscode on windows 10 - Stack Overflow
Did you use msys2 to install MinGW like the VSCode documentation tells you: https://code.visualstudio.com/docs/cpp/config-mingw ... followed it to the letter until I reached the part about how to write c++, and it seems like the entire program has just stopped working ... "udenfined reference to 'WinMain" What command line did you use to build? Do you have an int ...
🌐
Graphicscomputing
graphicscomputing.fr › cgp › compilation › content › 02b_windows_mingw › index.html
Windows Setup (MinGW)
The general approach is to install a compiler separately, and add it to the Windows path in order to be detected by VS Code. - MinGW is an implementation of the Open-Source gcc compiler on Windows.
🌐
YouTube
youtube.com › watch
Setting up GCC with MinGW-w64 in Visual Studio Code on ...
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
🌐
Codedamn
codedamn.com › news › c programming
How to Set up Visual Studio Code for C and C++ Programming
November 28, 2022 - Here we will install the gcc and g++ compilers. To do that enter the following commands ... Enter y and hit the enter button to proceed with the installation. Once the installation is done check the version of gcc and g++ to do that enter the ...