Setup VS Code with C++ On Windows 11 (or 10)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to this short video where we'll be installing Visual Studio code and setting up msys2 to run compile and debug C programs on Windows these steps work for both windows 11 and windows 10. this video also has a companion article over at medium there's a free link to the article in the comments and description the first thing we're going to do is install Visual Studio code if you don't already have this you can go to code.visualstudio.com download and if you want a user version you're going to want to click the x64 user install or system-wide version you can grab this one I'm just going to grab whatever the default is by clicking the big button and by default they gave us the user setup this installation is really straightforward just accepting agreement keep the defaults for everything and let it ride and finish and we get to launch here they have you go through the setups you can do this if you want to set up your your environment for me the most important thing is Select dark and now we're good okay now we have Visual Studio code open and for now I'm going to close this because we need to install msys2 and set up the environment variables which would require us to reload the terminal anyway so I'm just going to close vs code and now let's go get msys2 mcsus2 is available for download from msys2.org there's a link in the description so we're going to grab the latest version from here once it downloads we're going to run it and just click next keep the default installation folder if you change this folder make sure you make note of where you install this program because you will need it to update your system variables or environment variables again we can keep all of the default installation options for msys2 just click through it and allow it to install I'll let it installs let's go ahead and grab our Command here it is finished installing let's go ahead and run it from the msus2 terminal we're going to run Pac-Man Dash capital S Ming w-w64-ucrt yes you see it so we're going to run this command to install GCC just say yes to accept the install and allow it to do its thing now that GCC is installed we can install GDB for debugging to install GDB for debugging we want to run this command we're provided with a lot of options here but what we're looking for is Ming ww64x8664 GDB so in this case we want option nine and again we'll just say yes to install and we just give this a minute to complete installation okay now that we've installed GCC and GDB we are actually done here we can confirm the installation by typing GCC version so we can actually close this and we want to open our environment variables so the easiest way to get to your environment variables is to go to the start menu and search for path or something like that you can also search for edit the system environment variables anything to get you to this menu from here we're in the advanced tab of the system properties we go to environment variables double click on path or click path and then click edit and this is where we want to add two new options and for that we want to add two items to the path first we add msys 64 UCR t64 slash bin then we also add C colon backslash m64 backslash Ming w64 backslash pin with these two items added to the environment variable list just click ok to get out of all of these menus and then finally we can go back into vs code to make sure that everything is working properly okay we are back in vs code and let's make sure that we can access GCC and GDB from the windows terminal this is just the Powershell terminal that opens with Visual Studio code you can press Ctrl tilde to open it if you don't see it and then we want GDB and we have both so let's go ahead and create a new C plus file and as soon as we create this file it's going to ask us if we want to install the recommended extensions for C plus just say yes install and there is this c c plus extension pack managed by Microsoft this is the one that you want and it's installing that if you were not prompted by default to install this you can always just go to the extensions area and search for C plus extension pack and find and install this extension pack provided by Microsoft but now that this is complete we can go back to our our program and start making it happen so let's just do a basic hello world program to demonstrate some of the capabilities so you can already see that we're getting autocompletes for our Imports here or the includes and you can see that we're getting Auto completes for everything we do so that's a good sign that it's working foreign together we should be able to run it by pressing F5 to run it in debug mode they give you two options for your debugger select GDB and then select your configuration it's going to be the first option which is G plus plus dot exe build and debug active file now the first time this thing runs it's going to open the debug console we do not need to configure cmake for this workspace and if we go over to terminal we'll actually see the output of the program and that only happens the first time you run the program each additional time you run the program it actually just displays the results in terminal as you can see here so we've demonstrated that autocomplete is working let's see if some basic error checking is working we're just going to try to include something that doesn't exist and you can see that it's underlining it with an error because this library is not on the path because it doesn't exist we can see that the autocomplete is working here but we can also just test it on an object so we can just create this empty vector and then try to add an item to it by pushing it to the back and you can see autocomplete for the vector object is actually working so everything is now working as expected we have shown how to run using F5 and it runs in debug mode but the only thing that we haven't shown is how to set break points so you can set a breakpoint by going over and clicking the Red Dot next to the line number or from any line number you just push F9 and then if you push F5 to run your program it should interrupt the execution and show our breakpoint here so now we have this Vector it's actually empty and then we can push an item onto it and we'll step forward with F10 and now we have pushed a single item onto our Vector somewhere there's the first value at the start but you can see now we are in debug mode and to continue running we can just push F5 and our program has exited as normal at this point we have finished setting up our c plus plus development environment on Windows using visual studio code and msys2 if you found this video helpful be sure to like And subscribe and also go over check out the article on medium there's a free link to the article in the description and the comment section thanks for watching see you next time
Info
Channel: KNuggies
Views: 12,255
Rating: undefined out of 5
Keywords:
Id: 4ridGE4jWi0
Channel Id: undefined
Length: 7min 12sec (432 seconds)
Published: Wed Apr 05 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.