(light music)
(keyboard clacks)
Frank: In this video,
I'll show you how to use the source code provided
for the course with Visual Studio Code.
First thing we need to do is get to the source code.
The source code is provided in the course content,
and you can see right now, it's in Section 22.
It's in a section called, "Extra Information,
Source code and other stuff."
And if you open that up,
you'll see that "Source Code for all Sections,"
and it'll bring you this page right here.
Don't go off of Section 22.
If I add new sections to the course,
that will get bumped down to 23, 24, 25.
So I'm not sure where that will be when you watch the video,
just look for, "Extra Information,
Source code and other stuff."
Open that up and you'll find the source code.
Once you do that,
there will be a link to a zip file
for the source code for each section in the course.
And if you want to download the source code,
just click on the link.
I've already done that and I've downloaded the source code
for Section 4 as a zip file.
And you can see it right here,
there's the zip file right here.
What I'm going to do is I'm just gonna double click on it
and that extracts the Section4 folder.
So I'm just going to select Section4,
and I'm just gonna move it over to my Desktop.
I'm just using the Desktop as an example,
you can move that to any folder you wish.
What's really important is whatever folders you create,
whatever names you use, remember, no spaces,
no international characters, and no special characters.
Otherwise, you may have build problems.
So now once we've got that on our Desktop,
you can see our previous SectionX course
that I created in the previous videos.
There's Section4, what we need to do now is we need
to open up this folder within Visual Studio Code.
You see, this folder has projects within it.
ChallengeSolution, CompilerErrors,
CompilerWarnings, and so forth.
Those will be the individual projects
that we'll also be using within Visual Studio Code.
So I'm just going to close this
and I'm gonna head over to Visual Studio Code right here
and I'm going to open Section4 from my Desktop.
Make sure you open the Section4 folder,
not the folders within Section4.
So I'll select Open and there we go.
You can see that the folder structure has now been opened
within Visual Studio Code.
And we just make this a little bigger.
So you can see that Section4 right there,
and within Section4,
you've got the projects that I mentioned.
We also have some other files.
We have this .codelite folder
and this Makefile and Section4.workspace and so forth.
Those are all CodeLite files, don't worry about those.
You can remove them if you like
or you can just leave them in
and you can use your project with Visual Studio Code
or with CodeLite.
Visual Studio Code will just ignore those files.
Okay, so what do we do next?
Well, we need to configure Visual Studio Code
to think of this section as a C++ section, right?
So what we need to do is we need to set up IntelliSense,
we need to set up our default build task,
and if we want to debug,
we need to set up our launch.json file.
There's a couple of ways we can do that.
We can do it manually just like we did
in the previous videos for this section,
and that's what I'll do here again,
just so you see it one more time.
Or you can grab that .vscode folder
that you've already created in those other projects
and just move it into here.
Just copy it right into Section4 and you'll be good to go.
But I'm gonna do it one step at a time.
So let's do that.
So the first thing we'll do is we'll open up any one
of these and I'm just going to open up,
let's say FirstProgram
and select the main.cpp file within it.
That's the program we'll use to configure.
So what we'll do first is we'll go over here to View
and the Command Pallete and we'll type C++.
And again we're looking
for C/C++ Edit Configurations UI right there.
We'll select that,
and then we wanna be sure we're using g++.
So you come down to Compiler path, and whatever's there,
just change it to g++, we've got that.
Then we'll scroll down a little bit further
and look for the C++17 standard and we'll use c++17.
That's it, I'm going to Command + S to save it
and I'll close that up.
So notice now our .vscode folder has been set up
with our cpp_properties JSON file.
So we're good to go here.
Now what we're going to do is set up the default build task.
So again, click on that main.cpp.
This time, you go up to Terminal and down at the bottom,
Configure Default Build Task, I'll select that.
I'm going to use g++, so I'll select g++.
And this is the file we're gonna make a couple
of changes in, in the args section here on line eight.
We're going to add dash W-A-L-L with W
as capitalized and we're going
to add -std = c++17
to tell the compiler to use the C++ standard just like that.
If you're typing anything,
and you see squiggles like you're seeing right there.
That means there's a typo somewhere.
You might've forgotten a quote mark or a comma.
In this case, it's the comma.
Then what we'll do is we'll take this fileDirname
and we will copy that right into line 12
and replace file with fileDirname.
And once we do that,
we have to add our /*.cpp to tell the compiler
to compile all the files in there.
That's it, so now we're done with that.
We can now build our project. Let's try it out.
So I'm gonna close this out
and I'm gonna open my main.cpp again.
Now once I'm here,
I can come up to Terminal and run the build task
or you can press Shift + Command + B.
You can see down here,
we've got a build and it was successful.
Always double check.
You've got your -g, your -Wall,
you've got your standard c++17,
and we've got our CPP files being compiled.
At that point, now we have this main executable
that was created for us right here inside project one.
So I can right click on that
and open it in the integrated terminal.
We can do an ls to see the files that we've got,
and we've got several files.
Some of them are CodeLite files.
Don't worry about them, this .mk and the .project file.
But we do have our main executable right here.
If we wanna run it, we just type ./main and press Enter.
"Enter your favorite number between one and 100."
Let's say 45. "Amazing, that's my favorite number too."
And you can see from the source code up here,
that's exactly what the program's doing.
So that's it for configuring for the build.
Now in order to configure for debugging,
let me close this window here to make up a little more room.
What we can do is again,
we can select our main.cpp file and we can come up to Run,
Add Configuration, and select C++,
GDB, LLDB, and g++.
Now at this point,
we'll want to kill the debugger right here,
we want to use that little red square right here icon
to stop it.
And what we want to do is we want
to edit this launch.json file that was created right there,
which is open already.
The only thing we want to do here is we want
to change the type to LLDB.
(keyboard taps)
When we do that,
you'll notice we have some errors just like we had before.
In the previous videos, we just want to delete those lines.
We don't want any squiggles
or any red markers or anything anywhere.
That's it, your current working directory
should be fileDirname, make sure that that's correct.
If it's not, you can change it to that.
And that's it, I'll save that and we'll close this up.
And now we can debug this program that's open.
So I can click on the program,
and then select the debugger right over here on the left,
that bug, play icon, run and debug,
I can select that and it's waiting for us now
to execute it by clicking on that green arrow up here.
I do wanna put a break point in.
So let's put a break point right here on line seven.
You can come across here, you'll see that red dot.
There's a break point showing up down here.
If you see a lot of other break points from other projects,
clear them out.
And then just come in here
and select the break point you want.
At this point, we can run it.
So we'll just click on that red arrow.
The debugger will engage, this bottom bar turns orange.
You can see favorite_number up here, set to zero.
We never initialized it
and we'll talk about that in the class.
Our current executing line is line seven.
So we can execute it by just stepping over
by pressing this icon right here.
And the output will be here in terminal.
So you could always click there.
So I'll do that and I'll do it one more time.
It's asking me now for the favorite number.
Again, I'll type 45 one more time.
And when I press Enter,
now you'll see that I'm stopped at line nine
and favorite_number's value has changed to 45.
And as before, we can, you know,
hover over that variable name and we can see our value.
To finish the program,
you can click the play arrow
or you could just stop it right here in the debugger.
I'll just continue. That's it, so there you go.
This video shows you how to set up the source code provided
for the course to work within Visual Studio Code.
So now we can edit, we can debug, and we can build and run.