A Visual Studio Code configuration that allows the .c/.cpp files to be compiled and the '.exe' file to be executed, will be created with the same name as the base .c/.cpp file.
- MingGW (As it is setup to work with MinGW on Windows)
- VSCode
- Add MinGW directory to 'PATH'. (Google how to do it if you do not know)
- Just get the .vscode folder cloned in your current C/C++ project directory.
If you want to set it manually, follow the instructions:
-
Open the folder you have/want to begin the C/CPP project in VSCode.
-
Open Power Command Palette (Ctrl+Shift+P) and type 'tasks' and select 'Tasks:Configure Task'. It will open the 'tasks.json' file in VSCode editor.
-
Replace all the code with the following code:
{ "version": "2.0.0", "tasks": [ { "label": "echo", "type": "shell", "command": "g++", "args": [ "-g", "${fileBasename}", "-o", "${fileBasenameNoExtension}" ], "group": { "kind": "build", "isDefault": true } } ] }
-
Open Power Command Palette (Ctrl+Shift+P) again and type 'launch' and select 'Debug:Open launch.json'. It will open the 'launch.json' file in VSCode editor.
-
Replace all the code with the following code:
{ "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe", //change this if you have a different installation folder. "preLaunchTask": "echo", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
-
Open Power Command Palette (Ctrl+Shift+P) again and type 'configurations' and select 'C/Cpp:Edit Configurations'. It will open the 'c_cpp_properties.json' file in VSCode editor.
-
Replace all the code with the following code:
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "compilerPath": "C:\\MinGW\\bin\\gcc.exe", //change this if you have a different installation folder. "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "clang-x64" } ], "version": 4 }
These files will be created in a folder named '.vscode' inside the project directory.
Now you can get your C/C++ project up and running with proper file names and degugging enabled.