In this video, we'll take our first program,
which we've compiled to show that it's got no errors and we'll build it.
Now if you recall building means
compiling, linking together with extra libraries
and external files if we need to and creating an executable file.
That's what building is all about.
There are several steps involved with building.
The first one obviously is compiling.
If we can't get a clean compile, then there's no way we're going to build the system.
So we want to be able to compile and then link
to create the exe file. Finally, we can run our executable.
So in this case, you'll notice here's the source code.
And there's a lot of space in here. Normally, we don't have all this space in here.
I just put it in because it makes a little bit easier for you to read
when you're first learning. So let's just keep it like that.
This program is exactly the same as it was before.
We're entering -- we're asking the user to enter their favorite number between 1 and 100.
We're getting that number and storing it in a variable called favorite number.
And then we're just saying amazing that's my favorite number too. So it's really really simple program.
And we've already compiled it.
There's a couple of ways to compile.
One is you can come to the source file itself, right click,
compile or you can come up to build,
compile current file
and that's only taking care of the compilation.
There's also a lot of things you could do at the project level right here. So if I select the project
and right click, you can see that it says build,
rebuild, clean, stop build and so forth.
Let's talk about clean first.
think about this. When I compile
a c++ program, I'm converting the cpp source code,
this source code you see here, to an object format, right. A machine
language or a binary format.
That's going to create a .o file or a .obj file, as we mentioned in
previous lectures.
That's the purpose of compiling.
Now as your programs are compiled,
they will have many of these .object files.
The clean process removes all those object files
and puts your project in a clean state.
In other words source code only. No object files.
Now why is this important.
It's important because when you compile your programs
and build your programs,
sometimes you want to do a clean build.
What that means is I want to start from a
position where nothing has been built. I just want to clean everything out.
Now when we're working with a single cpp file like here,
it's pretty much a moot point because it's just one file.
But typically, c++ programs are very large
and you've got a lot of c++ files.
Each one of them is being compiled to an object format
and when you say, hey compiler build for me,
the compiler is only going to build exactly what it needs to build.
So if it realizes that this source code
already has an object file associated with it
and the source code hasn't changed, then why bother building it again, right.
So it's not going to build it and it does that to be efficient, which makes a lot of sense.
But occasionally, you want to do a clean that removes all of that stuff.
It removes the exe that was created.
And then you want to build again. So now we're going to get a clean build.
Again, this is really not an issue here when we've got one cpp file.
But if you've got thousands and thousands and thousands of files,
there can be a significant difference in the amount of time
that it takes to do that build.
Okay. So in this case, I can come over here to the project.
I could right click, and I can say clean.
And you'll see here the clean is complete.
All it did was remove any object files and all in the exe files.
Then I can say build.
Now when I say build,
by saying build project here pressing F7
or on mac whatever the option, command option is
or I can right click on the project and say build.
Now what's going to happen here is it's going to go through
your project looking at all the c++ files
and only build what it needs to build.
Okay. Now in this case it's going to build everything because it's just the one file and I haven't built it yet.
But it's going to not build what it doesn't need to build and that's important to understand.
Rebuild is the combination of a clean and a build.
So when you say hey rebuild the project, it's going to do a clean,
it's going to clean everything out and then it's going to build it again.
For the beginning of this course, all of these are going to be just fine.
You can use rebuilds because it's going to be pretty quick.
Finally, once we get a build, we can run the project.
The way we do that is we come up. Again remember, we've got the active project here.
I can come up to build and run.
Now if I do that now,
we have an option we can simply execute the exe file
if there if there is one there or we can choose to build and execute.
I would generally tell you to select build and execute
and probably remember my answer don't ask me again would be a pretty good idea
because most of the time our files are going to be fairly smalland the
build is not going to take any time at all. So we can build and execute.
Okay. So that's how you run.
Let's say, I want to do that. Now I'm going to say build and execute,
and there's my program it says,
enter your favorite number between 1 and 100.
Let's say I type in 24, press enter.
It says amazing, that's my favorite number too.
Now this time elapsed is how long the program took to run.
This is being displayed in the latest version of CodeLite.
Prior to this last version, you didn't see that and I think it's windows only it's being displayed.
I didn't see that display on a mac.
When you run the exe file that's created from the command line,
you don't see that. That's just mostly for fyi.
So that you can tell as a developer
if there's something wrong and how quick your program is running.
Press any key to continue, I'm done.
Okay.
Now one of the things that I want to show you. Notice this workspace view,
which is where I'm at right now.
And again, I've got three projects here. Each one has a main.
Where's the exe files. Where are the object files.
Where's all that stuff. They should be there, right.
Absolutely, they should be there. And they are there.
The IDEs
generally hide that information from you because you don't need to know about it really.
I mean do you care that there's an object file or an exe file, really what you
care about is these error messages and so forth.
But we have this explorer tab
and that'll let you see all that I want to show you what that looks like.
You can click on the explorer tab
and then you can drag any folder from your operating system, from your file system onto here.
So I can just right click, open folder
and I'm going to select from my desktop cpp examples
that section 4 folder.
That's where my workspace is, and I'll select it.
Okay. So you can see now if I expand this,
you could see a bunch more stuff. Now I've got a .codelite folder that has
things that are related to my favorites and compilation
and refactoring and so forth.
I've also got my three projects, first program project1, project2.
I've got a make file. I've got my workspace file
but let's look at first program for a second.
Now you can see a little extra stuff going on, right.
Before all we saw was main cpp. Now we see all this other. Stuff
these are the files and the configuration files that CodeLite is using
behind the scenes.
The IDE workspace here
abstracts that out since you don't really need to know all that information
to build your system. It's building it for you.
But if you really want to see them you can or you can just look right in your file system.
Now if I look in my first program debug folder,
you'll see that there's my exe, firstprogram.exe.
You can see it right here. And there you can see my .object files and .d files and all kinds of stuff that's going on.
Now you'll see first -- again first program debug.
Now what I'm going to do now is I'm going to clean first program.
And all of this stuff should be removed.
So again, I'm going to go to build,
clean project.
Now if I refresh this view by right-clicking up here, refresh,
and go back to first program, you can see it's all gone.
The entire debug folder is gone. The object files are gone. The exe files are gone.
Everything's gone. So now when I rebuild, all that will be created again.
And now you'll notice that debug folder, right.
Well, if I come back to my workspace,
there's my first program. Notice that we've got
build configurations here. And there's a couple you've got debug and release.
You can choose either one.
We're going to use debug throughout the entire course because that's what we're doing.
We're basically developing right here.
Release is when you want to release the file from two productions for your users to use.
So in this case, debug creates that debug folder that you saw a little bit ago.
If we do this in release mode, we'll get a release folder as well. So we'll have two exes.
Now the difference is the debug configuration
creates object files that has debugging information in them.
It's got all those variable names and stuff.
So later on when we debug our program,
we can have all that information available to us
and it makes us very, very productive.
And it really helps us debug and test our code.
The release configuration removes all of that stuff.
And it does more optimizations.
And it just makes your exe leaner and meaner. So that you don't need all
that debugging information at runtime.
Okay. So like I said we're going to use debug.
You can certainly use this if you like
if you do use this because you're curious or you want to see what's going on,
don't modify anything from in here.
I mean as a matter of fact if I try to open up this make file,
you'll see it says auto generated by CodeLite. Don't change it
or even if you do change it, we're going to blow it away anyway.
So you really don't need any of that.
This is where we're going to be working in the workspace mode.
But I just wanted to show you how that clean really, really works.
Okay. So again, let's recap here.
I can select first program. Right click,
clean.
That'll remove all my object files in the exe file.
I can rebuild in which case it will clean and build
or I can simply build and that will only build what needs to be built.
Okay hopefully, that makes sense. It's a little difference between them.
But it said you should understand it's not that big that big a difference.
Now finally, we want to run. We come here to run.
So let's do this one more time. I'll build and execute,
enter your favorite number. My favorite number is 100 this time.
Amazing, that's my favorite number too. That's exactly what our program is supposed to do.
Now you'll notice a couple of things here.
One is we're really not using favorite number,
are we? I mean the user is typing it in, but we're not really saying
wow that's a great number 13 that you entered or 100 that you entered.
And you'll do that in the challenge exercise in this section.
But right now we're grabbing it, we're storing it into that variable.
But we're not really using it afterward.
And then, like I said, in the challenge video, you will use it.
So that's it. That's pretty much the build process, the compile process,
the run process. It's fairly straightforward.
If you've got the toolbar, you can click on buttons to do this.
But in this course, I'll come up here and do these things or I'll just right click here
and do what I need to do here as well.
That's it. Remember, you can also come up to the workspace,
and right click on the workspace, you can build
the entire workspace or clean the entire workspace.
And that will create exe files for all the projects, all in one shot.
Okay that's it for that.
Now in the next video what we'll do is we'll talk about
compiler errors and compiler warnings.
And we'll mess around with this program a little bit.
And I'll show you some of the common errors and some of the common warnings that you could get
as well as why they happen.
Now throughout the course, we're obviously going to see a lot of compiler errors.
I make it a point that when I teach I'm just coding
along with you.
So I hope I make some mistakes, so you can see some of the common
compiler errors.
I'm not trying to make them intentionally, but sometimes
you know you forget a semicolon or you forget to do this,
this is the wrong type. So that's important that you see these types of errors
happening, and you can know how to fix them.
All right. So I'll see you in the next video.