C++ Setup in VS Code with g++ and gdb on Windows 10

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi in this video I'll show you exactly how to set up visual studio code for building and debugging C++ programs to get started we first need to do a couple of things first we have to install Visual Studio code and C C++ extension this extension will be used for debugging and intellisense in our C++ programs you can get these things by following these two links next we have to also install mingw it contains the C++ compiler called G plus plus and the C++ debugger called gdb you can install mingw by following this link also make sure to install mingw in a path that doesn't contain spaces for example if you install it in Program Files mingw can have issues with this space so I installed it directly on the C Drive after completing this we have to add the bin folder that is inside of our mingw installation to the path environment variable so that we can execute the programs from mingw without the need to specify the entire path to the program so for example if I type in in command prompt g + + - - version g + + will not be recognized as a program so let's add the bin folder to the path environment variable by searching for environment in the window search and let's edit the user variable path click on edit and let's now find the bin folder here then in GW and here it is as you can see G + + and gdb programs are here so let's copy this path now click on new paste it click ok then again okay let's run CMD again and let's repeat the command 3 + + there - version and as you can see G + + command is now successfully executed now let's open our project folder by clicking on open folder let's select tutorial project that I've created previously don't save the changes here and let's configure intelligence in our C++ extension let's go to view command palette and let's type C++ edit and let's select the UI version of this command now let's specify the compiler path for our G + + compiler the path to our D + + can be selected by holding the shift key and right clicking on D + + dot exe and now let's select copy as path and let's paste it here but without the quotes down below for the intellisense mode we will select DCC 64 as you can see in our folder see the CPP properties that JSON file is created and it reflects all the changes that we've made for the compiler path and for the intelligence mode now we are ready to create our first C++ program so let's create a main dot CPP file let's make a program that prints the sum of two numbers on the terminal we should start it by including the iostream standard library please notice when I start typing how intelligence offers us code completion [Music] you to build our program we should create a build task for it to do it let's go to terminal and then configure tasks now let's select create tasks that JSON file from template and then go to others here we can specify our task for label let's just type in build and for the command we should enter G + + this g + + command can have several command-line arguments let's define them the first argument will be - oh and then the name of the executable file that will be created after the build I will just name it main the third argument is - G this is useful for creating debugging information which will be useful when we debug our program and the last argument is just main that CPP file also we should put our tasks in a group and that group will be the default build group here let's save the tasks dot JSON file and now we are ready to build our program let's go to terminal and then run build tasks and we didn't get any errors and our main that Exe file is created let's try to run it by typing dot forward slash main dot exe and the output is 5 as we expect from the sum of these two numbers let's also try to debug our program for that to work we have to make a debug configuration so let's just go to debug and then add configuration here let's select gdb and then the default configuration here we have to make some changes for the program name instead of a dot exe we must enter main dot exe we also have to specify the debugger path or the path to gdb let me quickly copy that path and let me quickly paste it here we also must escape the backslash characters if you want to select the next occurrence of the backslash characters you can just hit ctrl D and now it's really easy to add double backslashes let's save our launch dot JSON file and we are ready to start our debugging session but first let's create a breakpoint at the line 7 so our program stops here let's go to debug and start debugging and as we expect our program stopped at the breakpoint we can step through our program by hitting f10 and as you can see on the left side the values change for our variables and after we cross this line 5 will be shown here in the terminal okay so that's it for this video I hope you understood how to build and debug simple C++ programs in Visual Studio code please give this video a like if you found it useful and subscribe if you like to see more content like this in the future see you in the next one
Info
Channel: Codeflash
Views: 49,322
Rating: undefined out of 5
Keywords: vscode c++, vscode c++ setup, vscode c++ setup windows, vscode c++ compile and run, vscode c++ configuration, vscode c++ compiler, vscode c++ compiler windows, vscode c/c++ setup, vscode c++ compile run windows, vscode c++ debug, vscode c++ debug windows, vscode, c++, g++, gdb, mingw, path, coding, programming, computer science, tutorial, how to, codeflash
Id: ABVeAXcRIJg
Channel Id: undefined
Length: 9min 40sec (580 seconds)
Published: Fri Jan 10 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.