franneck94 / Vscode-C-Cpp-Runner

πŸš€ Compile, run and debug single or multiple C/C++ files with ease. πŸš€
MIT License
53 stars 14 forks source link
clang cpp gcc gdb linux lldb macos visual-studio-code vscode windows

VSCode C/C++ Runner

πŸš€ Compile, run and debug single or multiple C/C++/Cuda files with ease. πŸš€
You do not need to know about any compiler commands. 😎

Example

ExampleGif

Software Requirements

Make sure that your GCC/Clang compiler is either in your PATH or you have to manually set the C/C++ Compiler setting of this extension.
For Windows Users that want to use the Visual Studio compiler (called MSVC) see instructions here.
For Cuda code the NVCC Compiler will be automatically called.

The Extension automatically activates when

Compile a single file

1️⃣ Open the C/C++ file you want to compile (build).
2️⃣ Select either debug or release mode for building the binary (debug is the default case).
3️⃣ To build the binary press ctrl+alt+b.
4️⃣ To run the binary press ctrl+alt+r, or you can click on the play icon in the status bar down below.
5️⃣ To debug the binary press ctrl+alt+d, or you can click on the bug icon in the status bar down below.

Compile all files in one folder

1️⃣ Select the folder that contains the C/C++ files you want to compile.
You can select the folder by the quick pick menu from the status bar.
TaskStatusBar
2️⃣ Optional: Select either debug or release mode for building the binary (debug is the default case).
TaskStatusBar
3️⃣ Now you can build/run/debug the binary.
TaskStatusBar

*This task is a no-op if the build task was not executed previously.

Basic Features

Configuration

The configuration settings will be stored locally in ".vscode/settings.json".
FoundCompiler

Based on that, the local ".vscode/c_cpp_properties.json" file is created.
It will be used by Microsoft's C/C++ extension for intellisense (auto-completion etc.).
Note: You don't have to edit the c_cpp_properties.json file.

Basic settings

Using the MSVC Compiler

To use the Visual Studio MSVC compiler, e.g. VS2022, set the msvcBatchPath setting to a valid path.
As an example installation path of the compiler:
"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat".
Then set the useMsvc extension setting to true, to use MSVC and not GCC/Clang.
If you want to stop using the MSVC compiler, just set useMsvc to false.
⚠️ Only the 64-bit (no cross-compiling) version of MSVC is supported.
⚠️ The extension is only tested for VS2019 and VS2022.
⚠️ For auto detecting the installed VS you have to install it in C:/Program Files/Microsoft Visual Studio

Advanced Features

Passing Commandline Arguments

You can pass in command-line arguments for running or debugging the binary.

Alt text

Make sure to select the active folder that should be compiled beforehand.
Then press ctrl+alt+a to open the message box to type in the arguments:

Arguments

These arguments will be stored in the launch.json config for debugging the binary.

ArgumentsDebug

If you now run or debug your program these values will be fed into argc/argv.
Important: The stored arguments will be reset after selecting a new active folder.
Note: For strings with whitespaces please use \" (not single \').

Include & Exclude Folders for Selection

You can add glob patterns to include and exclude folders from the folder selection.
Note: The include pattern is used before the exclude pattern.

For example with the following exclude glob pattern:

ExcludePattern

The folder selection would change from left to right.

ExcludePaths1 ExcludePaths2

Generate Assembler Code

When executing the command: Generate Assembler Code.
The assembler code will be generated in a .s file that will be in the build directory next to the executable.
πŸ‘·πŸ» Note: Currently, this feature is experimental and only works for single-file builds.

Advanced Settings

Important Notes

Constraints with Files and Folders

CMake Projects in the Workspace Directory

The extension buttons are hidden if there is a CMakeLists.txt in the workspace root directory.
This prevents an overloaded status bar with a lot of icons due to Microsoft's CMake extension.
However, the user can trigger the start-up of this extension by executing the command: Toggle extension buttons in status bar.

Release Notes

Refer to the CHANGELOG.

License

Copyright (C) 2021-2023 Jan Schaffranek.
Licensed under the MIT License.

Supporting the Work

Feel free to donate, such that I have more time to work on my VSCode extensions.

PayPal QR Code

Or use the Link: https://www.paypal.com/donate/?hosted_button_id=3WDK6ET99ZQCU