Both Windows and Linux environments will utilize the GCC compilers provided by the GNU Compiler Collection; the source differs by platform.
Windows.
The development kit w64devkit (via MinGW-w64) is employed.
Download the ZIP file named
w64devkit-<version>.zip.
Linux.
Most distributions include GCC by default. If unavailable, install the “gcc” package using the system’s package manager.
After downloading and extracting w64devkit, add its binaries to the system PATH:
Avoid moving or deleting files once this configuration is complete.
Open “Edit the system environment variables”.
Append the bin directory of w64devkit (e.g., C:\...\w64devkit\bin) to the Path variable.
Alternatively, you could run
setx /m PATH "...\w64devkit\bin;%PATH%".
The Code Runner extension for Visual Studio Code is recommended. Configuration entries in the settings.json file follow.
For non-VS Code environments, equivalent shell commands are provided.
"code-runner.executorMap": {
"cpp": "echo Executing... && cd $dir && g++ \"$fileName\" -o main && .\\main.exe && rm .\\main.exe"
}
echo Executing...: displays a status message.
cd $dir: navigates to the file’s directory.
g++ \"$fileName\" -o main: compiles into an executable named “main”.
.\\main.exe runs the executable.
rm .\\main.exe removes the executable.
"code-runner.customCommand": "echo Executing... && cd $dir && g++ (Get-ChildItem -recurse *.cpp) -o main && .\\main.exe && rm .\\main.exe"
Recursively gathers all .cpp via Get-ChildItem -recurse *.cpp before compilation. Projects should reside in dedicated folders without spaces in their names to avoid execution errors.
Shell commands differ due to path conventions and absence of PowerShell’s Get-ChildItem.
g++ main.cpp -o main && ./main && rm ./main
Replace main.cpp with the actual source filename if different.
find . -name "*.cpp" -type f -print0 | xargs -0 g++ -o main && ./main && rm ./main
For large and complex projects, CMake remains the recommended build system.
A PowerShell function to automate this can be found in this Gist.