π Compile, run and debug single or multiple C/C++/Cuda files with ease. π
You do not need to know about any compiler commands. π
- π§ Any GCC, Clang, MSVC or Cuda NVCC compiler
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.
- There is a C/C++ file in the root directory of your workspace
- You open a C/C++ file in your workspace
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.
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.
2οΈβ£ Optional: Select either debug or release mode for building the binary (debug is the default case).
3οΈβ£ Now you can build/run/debug the binary.
- βοΈ Build: This task will compile all C/C++ files in the selected folder and will link them into a binary.
βΆοΈ Run*: This task will execute the built binary.- ποΈ Clean*: This helper task will delete all files in the build dir.
- π Debug*: This task will start a debugging session for the binary.
*This task is a no-op if the build task was not executed previously.
The configuration settings will be stored locally in ".vscode/settings.json".
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.
- βοΈ C Compiler Path (string, defaults to "gcc")
- βοΈ C Standard (string, defaults to the compiler's default, e.g. "c99")
- βοΈ C++ Compiler Path (string, defaults to "g++")
- βοΈ C++ Standard (string, defaults to the compiler's default, e.g. "c++20")
- βοΈ Debugger Path (string, defaults to "gdb")
- βοΈ MSVC Batch Path (string, defaults to "")
- βοΈ Use MSVC (boolean, defaults to false)
- βοΈ To enable Compiler Warnings (boolean, defaults to True)
- βοΈ GCC/Clang Compiler Warnings (string array, e.g. "-Wall")
- βοΈ MSVC Compiler Warnings (string array, e.g. "\W4")
- βοΈ To treat Warnings as Errors (boolean, defaults to False)
- βοΈ To disable MSVC Security Warnings (boolean, defaults to False)
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.
You can pass in command-line arguments for running or debugging the binary.
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:
These arguments will be stored in the launch.json config for debugging the binary.
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 ').
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:
The folder selection would change from left to right.
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.
- If the compiler has it implemented and only in debug build
- βοΈ Activate the address sanitizer
- βοΈ Activate the undefined sanitizer
- βοΈ Activate the leak sanitizer
- βοΈ Show detailed Information about the Compilation Time
- βοΈ Use link time optimization for release builds
- βοΈ Compiler Arguments (string array, e.g. ["-pthreads"])
- βοΈ Linker Arguments (string array, e.g. ["-lpthread"]).
- Note: It is expected to prefix the arguments with the appropriate flags (e.g. -l or -L for Gcc/Clang)
- βοΈ Include Paths (string array, e.g. ["path/to/headers/"])
- Note: It is not (!) expected to prefix the arguments with the -I or /I flag
- βοΈ Include Glob Pattern for the Folder Selection (string array, defaults to ["*", "**/*"])
- βοΈ Exclude Glob Pattern for the Folder Selection (string array, defaults to ["**/build", "**/.*", "**/.vscode",])
- π File extensions for headers: *.h, *.hpp, *.hh, *.hxx
- π File extensions for sources: *.c, *.cpp, *.cc, *.cxx
β οΈ Include paths and file names with whitespaces and special characters (e.g. &) can make the compilation fail
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.
Refer to the CHANGELOG.
Copyright (C) 2021-2023 Jan Schaffranek.
Licensed under the MIT License.
Feel free to donate, such that I have more time to work on my VSCode extensions.
Or use the Link: https://www.paypal.com/donate/?hosted_button_id=3WDK6ET99ZQCU