C/C++ Compile Run extension
An extension running on Visual Studio Code to Compile & Run single c/c++ files easily. This is a fork of danielpinto8zz6/c-cpp-compile-run that allows for on-demand compile checking of C/C++ files.
Compile & Run C/C++ opened file directly from the command palette or by pressing 'f6' or 'f7'
Additionally, you can compile the file without running it by pressing 'cmd-6' (for mac) or 'ctrl-6' (windows & linux). This gives you a linter like ALE or syntastic on vim, except only for C/C++ files. Linking is not done - only compiling.
- If you are on linux you must install gcc (see instructions)
- If you are on window you must install tdm-gcc (see instructions). Alternatively, you can also install MSYS2 with mingw(32|64), but please read the instructions to setup the path correctly.
- If you are on mac os you must install clang (see instructions)
How to use
Make sure you have .c or .cpp file open.
Press "ctrl-6" or "cmd-6" to compile the file only and delete any autogenerated object files.
Press "F6", this will compile and run the file using default arguments in settings.
Or press "F7", this will use the arguments you specify for the program.
If you want to register gcc/g++ path manually, you can set it under settings.
You can also set to save file before compiling.
||The C compiler path (e.g: /usr/bin/gcc or C:\TDM-GCC-64\bin\gcc.exe)
||The Cpp compiler path (e.g: /usr/bin/g++ C:\TDM-GCC-64\bin\gcc.exe)
||Whether should save the file before compiling
||The environment variables to pass to the compiler
||The C flags: e.g. -Wall. default: -Wall -Wextra
||The Cpp flags: e.g. -Wall. default: -Wall -Wextra
||The working directory for the compiler. Defaults to the file path
||The run arguments
||Whether should run in an external terminal
||Whether should show notifications
||Custom output location for the compiled file
For the working directory and flags, the following variables have special meanings:
$HOME resolves to your home folder
$ROOT resolves to the root folder
/; on Windows this is equivalent to
$PROJECT_ROOT resolves to your project root folder - if there is no project then it's equivalent to
$ROOT. Multiple project roots are not supported yet - for now it just uses the first root.
$$ resolves to a literal
Important: Only local folders are supported at the moment.
||Compiles and runs the file
||Check for compile errors only
||Compiles and run the file in external console
||Compiles and run the file specifying custom arguments and flags
- On Linux and possibly macOS, gcc and g++ might fail to find "cc1" and "cc1plus" respectively. You might see an error message such as below:
g++: fatal error: cannot execute 'cc1plus': execvp: No such file or directory
The solution is to explicitly specify the PATH in your environment variable to the "gcc" folder. or add this to your settings.json:
x86_64-linux-gnu/9 with the folder you see in your system. The folder structure takes the format
Refer to CHANGELOG