Hello everyone.
In this video, we're going to configure CodeLite
to work with the C++ compiler on Ubuntu Linux.
I'm running Ubuntu 22.04, which is Jemmy.
I've already opened CodeLite.
And the first time you run CodeLite,
you're going to get a setup wizard pop up window that pops up just like this.
If you don't get that, you can always go to help and run it from there.
We do want to run this setup wizard, so I'm going to click next.
I'm going to click C++ development and click next again.
And I'm going to ask CodeLite to scan my system to find compilers.
I'll click that button and you can see it found GCC 11,
which was the compiler that we installed.
Now, I'm going to rename that to just GCC,
that way it's consistent throughout the course but I'll do that in just a moment.
I'll select next here,
you can choose the color whether you want a dark theme or a Light theme.
I generally use a dark theme, but I think the Light theme shows up
better on video, so I'm just going to leave this alone and I'll select Next.
And on this screen, just click Finish.
Okay, so CodeLite will close down and open back up.
And now, what we want to do is?
We want to setup the compiler and we're just going to change the name.
So I'm going to come up to Settings and go to Build Settings
and there you can see GCC right here.
So I'm just going to right click and rename and I'm just going to call it GCC,
just like that.
And I'll hit OK.
Perfect.
Now, what we want to do is? We want to create workspaces.
The way CodeLite works is it's got workspaces.
And then in those workspaces, you can have many projects,
each project being a C++ program.
So, it's a real nice way to organize your work.
The first thing we want to do is, we want to create a new workspace,
now there's a lot of ways to do that.
I can click this big button right here, right in front of me,
I can also come up to workspace, new workspace and I can go to file,
new workspace over here.
A lot of different ways to do it, I'm going to just click this button right here.
Now, I'm going to select the C++ Workspace and click OK.
Now it's going to ask me, where do you want to store your workspaces?
You've got some choices here, you can put them on your desktop,
you can put them in your documents folder.
I'm going to put it right off of my home directory
right there and I'm going to create a folder there.
Let me click over here to create the folder and I'm going to call it Workspaces.
So I can create as many workspaces as I want in here and then
projects within each of those workspaces
and I can have everything nicely organized, so I'm going to click create
and I'll hit open.
So now, you can see that the workspace path is my
home directory followed by workspaces.
And the workspace name is going to be workspace One
or whatever you like.
When you're working on pointers, maybe you want a pointer as workspace and so forth.
And make sure that the workspace under a separate directory is checked
and I'm going to click OK.
And that will create my workspace.
And you can see it right over here on the workspace view, you can see
the workspace one.
Now, what we want to do is?
Create projects within that workspace.
So I can right click on the Workspace One and create a new project.
Or I can come up to file new project.
Again, a lot of different ways to do it,
I'm just going to right click here and say new Project.
And now, we get this new project wizard.
We know that the path is that Workspace One folder,
that's where my workspace is.
Now, it's asking us for the project name.
I'm just going to call it Project One, just like that.
Very important, I'm going to probably say this more times than you want to hear it,
but it's very important.
No spaces, no special characters, no international characters anywhere.
So, don't start putting plus symbols and dots and slashes
and dollar signs in these names
because that will usually mess up the builds later.
So, just keep them really simple,
make sure that they create the project in its own folder is checked.
Now, the category we're going to select is console
because we're going to be creating console based applications.
The type is going to be simple executable G++ right here,
The compiler is GCC that the one we just installed and renamed.
The Debugger is the GNU
GDB debugger, we only have one option here.
And the build system, we've got two options, we're going to select CodeLite make file generator.
I'm installing version 17.3 of CodeLite.
Previous versions had a default build system, it was called Default
and it worked great.
But in this version and going forward,
the CodeLite developer removed that default build system,
I don't know why did that, but we have to deal with it.
So, we'll make a few adjustments to the way we create new projects but it's pretty easy.
Once we have all that, make sure all this is correct,
you click OK and you can see now that we've got a new project over here, Project One.
And it's got a source folder and it's got my main.cpp file in it.
The main.cpp file is our source code.
Now, I'm going to make this a little bit bigger, so I'm going to go to settings,
colors and fonts and I'm just going to create
maybe a, let's see,
we can set that to 20 that should be nice and big so it shows up good on video.
And I'll select that and apply and then hit OK.
All right, so now, the font is nice and large.
So, first thing we're going to do is, we're going to delete this.
I'm just going to copy it all and just press delete.
Now you can see over here you have this black dot
that's telling you that this file has been changed.
So that what's on disk is different from what you're seeing.
Makes sense because we just deleted a bunch of stuff.
So, we want to be sure that,
whenever we see that, we save when we're done.
So, first thing we're going to do is, we're going to type in
a real simple Hello World C++ program.
The reason we do this is because it's simple
and if it runs and we see Hello World,
we know that our development environment is set up correctly,
so that's the reason for doing it.
At this point, just type along, follow along,
all the C++ will be explained later.
The point of this video is to make sure that our development environment is set up correctly.
So, I'm going to type pound, include
space left angle bracket, io stream,
and right-angle bracket.
Then I'm going to type using
namespace
std semicolon,
there's spaces between using
and the namespace and namespace and standard.
Now, I want to write my main function.
Every C++ program has a main function
and that's where execution begins.
So let's do that, we'll type int, int
space main,
left Paren, right paren.
And then we have an open curly brace
and you'll notice that CodeLite automatically closed the right
curly brace for me,
so that way they match.
Make sure you spell main correctly, make sure those are parentheses,
make sure you've got spaces where I have spaces and so forth.
Okay, so now, I'm just going to tab over and I'm going to type c out,
two
left angle brackets side by side, no space between them
and Hello World
and I want that within double quotes,
two left angle brackets again and then,
the word endl for end line.
Make sure that's endl and not end1, the l
and the 1 look really similar.
Then I'm going to return space zero and a semicolon.
That's it.
That's our simple main.
When we run it, we should see Hello World display on the terminal.
But before we run it, we need to configure this project and give it a few compiler settings.
First thing, though, is let's save this, so you can come up here to file,
save file or you can press CTRL S, I'm going to press CTRL S
and you can see that black dot is gone,
it might be a red dot on your system.
It was a red dot in my other system, but it's a black dot here.
In any case, you're going to see that dot there
when the file is dirty.
In other words, when it hasn't been saved.
When I've made some changes, but I haven't saved them to disk yet.
Okay, so now, let's set up the project.
I'm going to right click on the project
and select Settings.
You can also just click on the project and select this wrench right up here,
does the same thing.
At this point, my project settings window opens.
And let's go through this, the project type is executable.
The make file generator is CodeLite make file generator, the compiler is GCC.
The intermediate directory is blank, the output file says Project name.
And sometimes, you need to stretch this out, just a little bit
to see more stuff.
And I think that doesn't happen on Windows or Mac,
but it does happen on Linux sometimes, let me stretch that out a little bit.
So, all of this is the stuff that we put in earlier.
There's one thing that's really important is this one right here, the working directory.
We want to delete that the entire line
and we want to replace it with dollar,
left parentheses, project path,
right parentheses
where the p in project and the p and path are uppercase,
that's really important.
Okay, that's the first part.
The second part is, I'm going to come over here to my compiler, click compiler
and right up here where it says CC++ compiler, I'm going to click that line
and you can see these little button shows up with three dots in it, I'm going to click that.
Then I'm going to come over here in the compiler options and I want to choose
enable C++ 17 features.
This one right here, enable C++ 17 features,
std equals C++ 17.
That will tell CodeLite to use the C++ version of the compiler.
That's it, we're done.
We'll click OK, we'll click apply
and we'll click OK one more time.
At this point, we are good to go.
Now, I'm going to make this full screen here,
so that we have a little bit more room to see what's happening.
Now, we're ready to build our project.
The way that CodeLite works,
since it can have multiple projects in this workspace here,
of course we only have one right now, we'll create another one in just a moment.
It builds and runs the active project
and you can see the active project right there, it's bold and it's italicized.
So if I have a bunch of projects there's only going to be one that's bold and italicized
and that's considered the active project.
To make a project, the active project,
you can select it, right click on it and then come down here to make active
or you could just double click on it, simple as that.
Now, we're ready to build this.
So, we're going to come up to build
and I'm going to select rebuild project and I'll
talk about all of the differences here in a future video,
I'm going to select rebuild project.
And the output window shows up down at the bottom,
I'll stretch this out so it's a little bit bigger.
And you can see right here we're using the C++ compiler,
we're building project one main CPP,
we've got std equals C++ 17and all the stuff that we typed in,
so this is great.
We have a successful build, no errors, no warnings.
Now, I can run my program.
So let me close this up, again to give us a little bit more room down there.
And I'm going to go to build and I'm going to select run.
Do I want to build and execute or just execute?
I've already built it so I'm just going to execute it.
And we get a terminal window popup and it says Hello World,
hit any key to continue.
The Hello world is our program.
The hit any key to continue is what CodeLite puts in there
because otherwise it would just display that and close up the window real fast.
So, we press any key to continue, it closes the window and we are done.
So, that's it, simple as that, that's the way we organize this.
In a couple of videos from now,
I'm going to have a video that shows you how to create a project template,
so that we don't have to do the std equals C++ 17 part
which saves us a little bit of time.
Great.
So, let's create another project.
And the second project is going to be basically the same source code,
again close this down here.
So, I'm just going to copy this source code,
I'm going to press CTRL C to copy
and I'm going to go to my workspace and I'm going to select right click,
new project.
I get the same new project wizard
and I'm going to create project Two in this case.
Again, no spaces, no special characters, no international characters.
Make sure that create the project in its own folder is selected,
these settings should carry over from the last time we did this,
so we've got console simple executable G++, GCC,
the GNU gdb debugger and CodeLite make file generator.
We'll click OK.
And now, over here, you can see we have project Two
and it's got a source folder and it's got a main CPP.
Let me expand these, so you can see that they are two distinct projects.
Now if you look up here,
you know that this is the source code for project One.
You can see that right up here in the tab.
And if I double click on this main CPP, it will open up next to it
and that's project Two, so this is project One's main,
this is project Two's main.
So, I'm just going to grab all that and paste
the other one that I copied into it and I'm going to say Hello World
from project Two.
Notice the black dot up here, so I'm going to hit CTRL S to save.
Now, I know that I've saved this.
Now, we're going to do the same thing, we're going to set up project Two,
so I'm going to click on Project Two, click on the wrench
and right here, you can always see up here it says project two settings
and this really stretched out that time.
There we go, let's try that.
So again, general, we're going to come right here to working directory.
I'm going to delete that and I'm going to type dollar
project path
inside parentheses with the two p's uppercase.
That's it. Then I'm going to go to my compiler,
go to my C++ compiler options,
click that button with the three dots,
select enable C++ 17 features stood equals C++ 17.
Click OK, apply, click OK.
Now, we're ready to build
but we have to wait a second,
we can't just build now, because if we build, the active project will be built.
And that's project one, you can see here.
I don't want to build Project One, I want to build Project Two.
So, what I can do is?
I can right click on Project Two and make it active
or I could just double click on it.
When I double click on it, you can see that it's now the active project,
it's bold and italicized.
So I can come back up to build, I can select rebuild Project,
we have our build output down here and you can see that
Project Two has been built right here.
We've got all the options we want, so this is a good thing, I'll close this up.
And now, we're ready to run, so I'm going to go build and run.
I'm just going to execute and now,
we should say Hello World from Project Two, which is exactly what we see.
We can press any key, I'm just going to press Enter to close this down.
So that's it, we've got our build environment working.
Now, we can start writing code.
The other thing that I'd like you to do is go up to Settings
and Preferences
and come all the way over here on the right to miscellaneous and just click that.
And in startup right here, there is a check for new version on
startup and I want you to uncheck that.
Otherwise CodeLite is going to ask you to upgrade to a new version every time,
there's a new version or a point release.
My advice is to resist the urge to update.
If you've got a working environment that's working
and you're able to use it to develop programs,
don't mess around with it.
Just use the same development environment throughout the course.
Sometimes we think that the upgrades are better.
A lot of times upgrades are bleeding edge and they're full of bugs and
they're not really worth the trouble.
So once we've got
a working development environment, leave it alone, it works great.
I'm going to apply, click OK.
And that's it, we're ready to go, our build environment is set up.
One more thing, when I build, it's possible that we have errors, right?
Of course, we can have typos, we can have syntax errors.
So for example, suppose I forgot that semicolon right there,
I can come up to, first I'm going to save
and there's a little red arrow there that's telling me there's a problem
there's expecting a semicolon after namespace.
That's not the compiler,
that's the CodeLite IntelliSense,
if you will, which is kind of going through our code and looking at it and trying to help us out.
But if we build, you can see that we have a syntax error.
It says expecting a semicolon before the int
and we have an error and our program did not build correctly.
So we don't want to run this program until we fix the error.
There are a lot of errors that we can get, and we'll do a whole
video on just the kinds of errors that you'll see common errors.
This is one that's really common
is forgetting the semicolon at the end.
A lot of student spell io stream wrong and they put io steam,
so that's a problem.
If we misspell Main,
you can imagine if we put spaces between these two angle brackets,
if we forget one of these parentheses,
so there's a lot of places the syntax has to be just right.
But again, we'll talk about all of this in the course.
At this point, you're good to go.
If you have any questions or any issues, please post them in the forum.
Look on the forums, because just about every question has already been asked and answered.
But if you have a question that's not out there, please post it and I'll be happy to help you.
The next video, you should go to in this section is
the video that shows how to create a default project template,
so I'll see you there.