Debugging a C++ (CMake) Project in Vscode

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hey so I wanna show you how you can debug a C++ project on Visual Studio code specifically projects that were configured and built using Simek this is for linux but it should work on Windows or Mac as well because I'm using platform-independent tools and I've seen other videos I've seen other videos about this but I thought they were kind of confusing and sometimes too general so yeah so let's start I'm gonna open up the terminal and this is my project folder right I'm gonna open yes go to you and here it is so yeah so this is my this is my code this is my project and just to give you a little bit of context this is a networked neural network proper I load a tensor flow model and then run it to classify images yeah to label images using the network prediction so so yeah so this is the Simek list file it's not too complicated has include the test flow library OpenCV package and it has two targets two executables hmm first thing we're gonna do here is I'm actually going to compile this so I'm going to create the build folder and then configure it and just to make sure it's running properly so here I'm gonna we have both a classifier test and webcam tests and if I run the classifier it runs fine and it works right mm-hmm so yeah so now I'm gonna show you so but what I want to do here is I want to be able to debug this file this is the classifier I want to be able to run this line by line and stop on this breakpoint say so base basically debugging the first thing you might want to try to do is use this function here so it prompts me to create a JSON file so I click here click here and we get an error and the error is it couldn't find this file the C API file so if I come here today I'm gonna show you the problem I'm gonna go to the finish of this header and here is the file I click on go to definition you can you can't find a file so even though I'm able to configure and compile this fine vs colleges are able to fight to locate this file and the reason is there is no the vs code is not aware of the configurations of C make and in order to be able to have the right to have debugger and functioning working correctly we need to give this awareness and to do that one thing we can do is install this extension C make tools which is very useful extension and I had disabled it just to show you the error and it's this icon here is the extension so the first thing we're gonna do is I'm gonna delete delete the old files are created and also I'm gonna delete the build folder and if I click on the Simic icon and click on configure all projects it's gonna basically find all the targets and also here down below I have some new options so I can actually build the the whole project or I can select a target that I want to build and without having to type anything in the terminal so I'm just gonna do this we're actually going to build all the targets and I'm gonna close this terminal yeah so it's it's built just fine let's try let's tested and classifier so works perfectly and in order to debug so the first thing we're gonna do here is I'm gonna debug the classifier I come here I want a debug class so I right-click on it and I click on debug and yeah so it's debugging just fine I can click on here and step over the functions I have all the current variables on this context the labels and data vectors and stuff and this is that's it that's basically it that's this is debugging in Visual Studio code supercilious okay so thanks I just want to show you one more thing it which is actually I wanna show you when I run this line I'm actually gonna get an error right so as I showed you when I run on the terminal here the program I don't get an error but here I got an error which is yeah debug console yeah I got an error here if I run again just to show you the error you can see the error message because it closed so if I click on run on terminal I get this error error regular file not found no such file or directory basically this is because as you can see here this was the line of terror I'm trying to load the model and this is the relative path D'Amato but this is relative to the executable file and when we debug the debugger will run from like if I come here and I on this image and I right-click and click run from terminal or debug this is actually going to debug from the root folder and not beautiful so how can we change that well one way you could do is we could take off those double dots here and it would run just fine because this this is now relative to the root folder right but another solution is and I want to show you how you can debug this with using actually using the lounge JSON file so you have much more flexibility and you can change some things including the debugger of target folder right so I'm gonna do is I'm gonna come here on the browser and this is the C C make tools website and this is their target debugging launching page and scroll down here they give us a lounge stock Jason template which I'm gonna copy and come here and create lounge dot Jason and paste it here so this is the template for debugging which is another way to debug but right and basically when I click on I'm gonna save this when I click on here on start debugging is actually gonna run based on disk configurations and I want the I wanna change to fix that problem I want to change the working directory out the target instead of being workspace folder I want to be gonna run it from workspace folder slash build right and the last thing I want to set is actually I wanna launch instead of watch launching the webcam I want to launch this target so right-click it and this has launched slash debug target right so when I'm click on play hmm this is actually gonna debug the classifier which is correct and if I come here and I go to that line that was giving giving me an error I'm actually able to to step over it and just just to show you that it fixed the problem I'm gonna run it that's how any breakpoints so it runs this fine we get the right result and if I want change back to let's say you want to change I want to debug this the web can target I set this as the default target and can come here and put it it's a breakpoint here let's say for the break one here and now I launch it and yeah so it's we're not debugging the webcam and I could continue going and yeah so now it's working on the webcam it's a bird okay so that was it and I hope it helped you and I see you next time goodbye
Info
Channel: D Bersan
Views: 31,487
Rating: undefined out of 5
Keywords:
Id: Rfj40xW9q6w
Channel Id: undefined
Length: 10min 15sec (615 seconds)
Published: Mon Jun 15 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.