Hello everyone.
In this video we'll configure code lights so that it will work with the compiler that we installed.
So obviously the prerequisite for this video is the compiler must be installed and code light must be
installed.
Okay, so let's get started.
I've got an icon here.
Shortcut to code light.
I'm just going to double click that and that's going to open up code light for the first time and it
says, Welcome to the setup wizard.
Let's run the setup wizard.
You only have to do this one time.
So I'm going to select next select your development profile, which is going to be C, C plus plus development.
I'll select next.
And now we can scan for a compiler.
Let's do that.
It probably won't find the compiler that we installed because it doesn't always find pre-installed compilers,
but let's try it.
And if it does find it great, if it doesn't, we'll install it manually.
So either way, we're covered.
So I'm going to select scan and it says it could not locate it.
That's fine.
Would you like to install one now?
No, we've already installed it, so I'll select next.
You can see that it found the Rust compiler.
That's a different programming language and that's okay.
You can just ignore that.
I'll select next.
Pick the color scheme that you want.
I'm going to use this default scheme.
Normally I would use the dark scheme because it's easier on the eyes, but I'm going to use this because
I think it shows up better on video.
I'll select next.
This dialog is asking you about white spaces and indentations and so forth.
Just leave the defaults as they are and click finish code light will close up and then it'll open up
again.
So now the first thing we have to do is since it didn't find the compiler in the setup, we need to
manually install the compiler in code line.
Really easy to do click settings and then build settings.
And then we click this blue plus symbol.
It might be green on your screen.
It depends on whether you've got the light theme or the dark theme.
So we want to click that right there.
Remember, we're on the compilers tab.
I want to click that, plus it says Add an existing compiler.
So I'm going to do that.
So after hitting the plus, you'll see this dialog.
We want to navigate to the path where we installed our Cygwin C compiler.
So I installed it in the C drive.
So you want to go down to your C drive and select that and then go to Cygwin 64 or wherever you installed
it.
By default, it's in C Cygwin 64, and then inside Cygwin 64 you have your bin directory.
From there you can just say select folder and then here you can actually name it, let's just name it
Cygwin Just so we know which one it is.
And we say, okay.
At this point, if you select the tools tab or if it's already selected for you, you're going to see
all of the build settings filled in for you.
Some of these are not correct, so you actually need to correct them.
The C plus plus compiler you don't care about, you don't need to worry about.
We haven't installed that.
But the C compiler, you actually want to use GCC.
So if you select the C compiler, then the dot, dot, dot, you can navigate again to the bin directory
and just select GCC dot exe.
So you go down there and you go GCC dot exe and that will run the GCC compiler for the assembly name.
You can actually just again, you can either use the dot, dot dot or you can just type it in in the
program you want to run as as ASX.
For the assembler name, the linker you want to use GCC.
So again, you can just manually edit or hit the dot, dot, dot.
You just want to make sure this is GCC dot exe for linker for shared object.
Again, we're going to use GCC.
So again, we can either use the dot dot dot or just say GCC dot x dash shared dash lowercase f pick
for the archiver we're going to go ahead and use again RDX.
With the RCU as a program argument.
The make we're going to use make X inside bin.
So that should be correct.
If not, it should be make dot x.
And for gdb we want to again modify that to use gdb so we can go to the dot dot dot go to gdb.
Dot XY and we can use that.
And then you want to make sure these settings are really important.
So you might want to pause the video again to make sure everything's correct again.
C plus plus compiler doesn't matter.
C Compiler GCC x assembler name ASX Xqcs Xqcs Xqcs shared for the shared object in the archive.
A.x.
And so then you can go ahead and hit apply and hit.
Okay.
All right.
So in Codelab, let me make this full screen here.
In code light, we've got several windows here and I'll go over this in more detail in future videos.
We have a workspace view and this is where we create workspaces, a collection of projects so we can
have a workspace with Project One and Project two and so forth.
And each one of those projects is a program that we're going to write here.
We can create a new workspace, open a workspace, and a lot of that you can also get to from the tabs
as well.
These modern user interfaces, there's usually 4 or 5 ways to do the same thing.
Okay, so let's create a new workspace.
I'm going to select new make sure you've got a C plus plus workspace.
That's what we'll be doing.
I'll click okay.
Now what's the path to my workspace?
I'm going to put it right off my user folder right there.
And what I want to do there is create a new folder where I can create all my workspaces.
So let's do that.
I'm just going to come in here and right in my home folder here, I'm going to create a new folder and
I'm just going to call it workspaces or my workspaces or whatever you like.
What's really important here is no spaces, no special characters, no ands and dots and all kinds of
weird characters.
Just name it a real simple name, like workspaces.
And that'll be fine.
That's it.
So I've got the folder.
I'm going to choose it.
And what is my workspace name?
Well, this workspace will be, let's say workspace one or Section one or whatever we want to call it.
I'm just going to call it Workspace one.
And you can see down here where the workspace is going to be created and it's going to create a workspace
file, make sure that this little check is checked, create the workspace under a separate directory.
That way we've got separate directories for all of our workspaces and it keeps us nicely organized.
I'll select.
Okay.
And you can see that this window now went away.
It's a big white area here and there is our workspace, our first workspace.
Now we can't really do much with a workspace.
We need a project within the workspace so I can select my workspace and do file new project.
Or I could just right click on the workspace and say new project and that's what I'm going to do.
All right.
So this is probably the most important part of this video is setting up the project.
So what is the name of my new project?
I'm going to call it Project one.
Make sure you create the project in its own folder.
And now we're going to fill in these dropdowns right here.
What's the category?
What type of application are we building?
It's going to be a console application.
That's a non graphical application that runs from the command prompt.
The next thing we have to select is the type.
And the type is basically going to be simple executable GCC.
This is a C program, so simple executable GCC.
The compiler that we're going to use, we just created the compiler that we're going to use and hopefully
you named it Cygwin.
So you can actually just go and select Cygwin.
If you left it default, you'd have to select that name.
The debugger that we're going to use is a new GDB debugger, and the build system that we're going to
use is we're going to actually use the code light Makefile generator Unix.
So again, this is, these are very important settings.
So again, take a look at these paws if you need to, but the categories should be console type should
be simple executable GCC compiler should be cygwin debugger should be GDB debugger and the build system
should be code light, makefile generator unix.
So we go and go ahead and hit.
Okay.
And so what you should notice is that inside your project one folder, you now have a source file that
was created called Main dot C dot C is the extension for the C programming languages.
And so that was automatically created for you and you can double click on it and then you'll see that
the editor comes up with a little tab project one main dot C and you'll see this is some C code.
The C code is not important right now.
We're just setting up our environment.
We're trying to make sure that we can build and compile and everything.
What you'll notice is if you try to edit this file, you'll notice when you write in code that there's
a little red circle up there, that means that the file is not saved.
You always want to make sure that it's saved before you build and compile so you can hit Ctrl s to save
it and you'll see the red goes away.
Right?
Or if you you want to save it as well, you can go up to file and you can just say save file.
So that red dot tells you whether or not your source code is saved.
Again, this is C code.
You don't have to worry about this.
We're just going to try to build and compile.
So you have your main dot C, you'll notice that you can actually change the settings of the actual
compiler and things like that by selecting the wrench up here.
So if you select the wrench up here.
Here you see all of your project settings and some of the things will automatically be filled in for
you.
So for you to general, you'll see some of the things that we automatically set when we installed the
compiler of Cygwin compiler.
So you see the Makefile generator is code light, Makefile generator, UNIX compiler, Cygwin and so
forth.
Most of these can actually just be marked as default and we'll actually go through a lot of these settings
maybe in a later video, but the general you should see basically filled in from what you did before
the compiler settings.
If you select compiler on the left, you'll notice that there are some command line arguments you can
actually pass.
We don't have to worry about C plus plus, but for C compiler options, if you select the dot, dot,
dot, it probably be a good idea to actually select.
The C 99 features.
So you can use like Boolean and things like that.
We'll talk about again that later.
So if you say enable C 99 features that will pass in a standard C 99 argument.
And if there's anything else, I don't think we really need anything else for.
The compiler options.
This is pretty much good to go here so you can hit.
Okay.
And then you'll notice it just passed in STD equals C 99.
Everything else can also stay the same if you go to the linker.
As far as linker options go, you may want to again go to the dot, dot dot for the linker options and
just select static linking.
That way we don't have any library problems later with linking mark that check static linking static
and again hit.
Okay.
And so we'll cover this more in more detail later.
But everything should be set up now so that we can actually try to compile and run our code.
So let's go ahead and hit apply and.
Okay.
And here now we see our source code.
So now we can try to build or compile our code.
And so if we go up to build and we say build project, you should see that the code is being built and
you should have no errors.
Because this is just a templated C code.
Now, if you were to add some syntax or something and you save the file and you try to build it again,
you may see an actual error.
And you also so you want to make sure that your code compiles by following everything.
So we can basically just modify the source code.
Say something like Hello testing and then go ahead and build the project.
You can always clean and build and we'll talk about these options later, but we're just going to build
the project and you'll see there's no errors and all our configuration was set up correctly.
Now, if you have any errors, they may be and they're not any syntax errors, they're actually something
wrong with the setup.
You'll have to go back and either go to the settings, go to the build settings, make sure that all
of your tools and your paths are correct.
You want to use GCS as make sure all that make sure the make file is make dot exe and everything make
dir should be blink.
You know you want to first check all those settings to make sure they're okay and then if you again
still have problems you can go back to the wrench tab and again go to the general.
Make sure using code light, make file generator, UNIX, you know, cygwin.
Again, these all should work by default, but you can just go and maybe play around with things.
If you keep having errors, post something in the Q and A if you can't figure it out.
But you should at this point be building successfully.
Now that I've actually compiled the program successfully, I can actually run the program and see what
the output is.
So I can highlight the project right here in the Workspace Project run, and I can go up to the menu
option under build and I can say run.
And once I do that, the program will try to execute.
This box will come up by default.
You can select the remember, so it doesn't ask me again.
You don't need to build an execute again.
You can just execute because since we already built it is two steps.
Or you can say build and execute again.
Either way it's okay, but you don't really need to compile again if you already did.
So I'm just going to say execute.
And now what you'll see is you'll see the sort of dos window come up with the output of the program,
which says, Hello, testing at the top.
A little bit difficult to read, but it says hello testing and it also has additional information with
it.
It says program exited with X code zero.
That's a good thing because it means that it was no issues with running the code and it returned zero.
And so there's a zero there.
It also tells you how long the program actually took to run and then press any key to continue.
Now, if we were to run this program from the command line, we wouldn't see this extra output.
We would just see, hello testing because that's the output of the source code.
But the ID code light comes with some extra information that's nice to have, but we don't really need
that information so we can go ahead and press any key to continue and this box will disappear like that.
And so that's how we can run our program.
And now they're also, you'll notice at the bottom a lot of different tabs and information.
The two most important tabs down here are the output tab and the build tab.
The output tab tells you kind of what's going on.
You know, it says, you know, your program exited and so forth and you're running things.
The build tab is basically what happens when you compile it.
And so if whenever you compile and you say build and you say build project, you'll notice it tells
you how to compile.
In this particular case, I'm missing a semicolon.
So there's an error there.
And it's kind of tells you there's an error.
So on a successful build, let's say we add the semicolon, we say safe and we build it again.
What you should notice on a successful build is you see the exact command that's being executed, which
we already set up in our settings, right?
You see, GCC dot x dash C is for compile.
It's compiling our source file, main dot C, It's using the program arguments that we set in the settings
for build G dwarf two standard C 99 dash wall.
Right.
It's all coming together, all those settings.
And then it also has GCC X, which is then linking it's the dash o option.
And then you see dot dash static, which we also added.
So all this is kind of coming together through the settings.
Now, as I just showed you, if you don't compile successfully and you have an error.
So for example, just like I had earlier, you don't have that semicolon, you're missing it now when
you build, you'll see that there's an error.
There's no actual semicolon.
It kind of tells you error expected semicolon before return.
And this happens a lot, right?
These syntax errors is what you end up seeing.
And this is typically if you do have a problem running your program, this is what you could post in
the Q and A the build tab.
And I can actually see what's going on to help you out.
But syntax errors are common when you write your C code.
And so understanding the compiler and the compiler errors we're going to actually go through in a future
video.
But this build tab is important to kind of see the output and whether or not you successfully compiled
or you have errors.
Again, common errors, missing the semicolon.
Sometimes students will forget that the D and standard i o.
So they have the semicolon.
I save it and they build it, you know.
And you'll notice that red arrow moves because the red arrow tells you where the error is.
The compiler will actually tell you.
So here in this case you misspelled standard IO.H, which is a C package that you can include, right?
And if you're missing the semicolon, the red arrow would be here, right?
But again, you save your compile and you run again, right?
And so once we fix these errors, we then can build project again or we can rebuild projects is another
option.
Well, it rebuilds everything.
It cleans it and rebuilds it.
And then you can see the outputs.
You can see successfully no errors.
And then again, you can run it just like before, build an executor, just execute.
So this is how you can compile and run your program and set up all your settings.
Now, if you have any issues at all, please post to the Q&A.
A lot of these questions have been asked and answered, so you can kind of look at them, whether or
not it's setting errors in your build environment or whether or not it's actual code and you have syntax
errors.
You know, there's all sorts of different syntax errors that that can happen.
And we're going to learn that as we go through the course how to write proper C code.
But the build tab is important, the output tab is important.
In subsequent lectures, we're going to go through how you can actually set up a template so that you
don't have to necessarily do all these settings and so forth.
When you create projects, you can just create the same project over and over again.
The code here you might not understand, but hopefully at the end of this lecture you're able to.
Get this up and running and running a simple C program.
Thank you.