make, compile, run Lab

FacebookTwitterGoogle+LinkedInEmail
Description
This lab demonstration video takes you through the basics of writing a standard “C” program, compiling and then executing it.  The demonstration uses a straightforward Print Statement to show you the basic fundamentals of writing a C program. [toggle_content title="Transcript"] Hi Leo Dregier here. I want to talk to you about writing a basic c program, compiling it and executing it. We are going to take a very simple approach we are just going to do a simple print statement but I want to kind of take the mystery of how to write a basic c program. So if you are through with c programming you may want to skip this video or continuing watching it for accuracy. But basically what we are going to do is we are going to go to our desktop inside or our Kali Linux image. We are going to right click - so new document and just select a new empty document. You call this whatever you want - typically it would be the name of your program. So we will do Cybrary.c is the name of the program and you can see it changes its icons a little bit different it we were to change it to something and rename it to something like TST. You know it will change the file extension but we can go ahead and leave it as a .c but this is again un-compiled code at this point. So go ahead and open the file up - you can double click it or edit the file or open with any basically any editor that you need will be fine. So the first thing that you want to do is basically include some of the header file information and to do that - let us do that again. So what we are going to do is basically include some of the - header information. Now these are good to have because they basically c code exactly where to start and what to reference and it really depends on what compiler you are using. But it is - just a practice to have any sort of programming. So the pound sign is going to be common these are going to stripped out when you are trying to compile your code or should anyway but then again it probably depends on a compiler. So we are going to go ahead and do a pound statement which is common and we are going to include with a bracket a standard input and output.h file and we basically just do a stdio .h and then include that with a less sign and a greater sign stop brackets. Not to be confused with some of the other brackets that are available. But nonetheless these are the header files - these are also part of the preprocessors which are used when you are actually compile your code. So the common ones that you want to start getting a practice or would be the standard input and output and the standard libraries. So go ahead and install which two comments includes http:lib.h now there is a little bit of a variance if you are going to use single quotes or less than a greater than signs. It just depends if things are already in your path or already not in your path. We are not going to cover that here but just wanted to make a quick reference of it. So it is basically standard input and output standard library header file. Then we can go into just writing some basic code so we can do initialization, name and then go ahead and do two brackets and notice they highlight here start and stop. Let us hope for the reference to make sure you don't have an extra bracket somewhere. So then we are going to add in another bracket and then we are going to do a print statement. So we are going to go printf, open the bracket and we are going to do cybrary.it is cool\' and then go ahead and end that and then and you notice that they highlight start to stop that is make sure yet again. You are consistent and then go ahead and add a ; to the end of that and then hit enter. Do a return - 0[]; and then go ahead and finish the statement which you notice get highlighted as well here and here. I mean that is the basic code and this is as basic as it is going to get. Because all we are doing is basically we are going to compile this code and we execute it. It is going to print the statements of term outside that ips school and then they go. So pretty basic, pretty straightforward. So go ahead and then click file and then save and then open up a terminal and if you do a print working directory of c and the root. So we are going to change directory to desktop. So that way we can actually see that our source code or cybrary.c is actually available and then we are going to go and get an installer. Now calli linux has the gcc compiler already located in it and you can prove this by doing a locate gcity. If you get a whole bunch of stuff back like I did - clearly you have something - you have not found them means. You don't have it - so I am going to scroll back up and going to make some sense for you. So here we go - locate gcc so the first thing we see here is basically some opt firmware and we can go ahead and skip these but you can see things like make file cc and things like that. We are going to scroll down user bin there is lots of gcc and bin directory or the binary directory they have lots of libraries support. So that is a good sign as well - again you would not see any of this if gc was not installed on your system. No matter what system you would be using. So and then of course a whole bunch of de package information which is where lot of the libraries are kept and you can see a bar library. So no less improving here is that gcc is installed. Now if I clear the screen then I want to actually install this we could do a pseudo apt get installed build - essentials and I am going to do this with a pseudo command and I am already locked in this room and I am going to spell it correctly. Build essential and I am going to spell install correctly and you can see that it would go out and look for it and it will say build.essential - this is another way that you could check but if there wasn't then by typing this command apt -get install build -essential that would install the necessary compilers, unnecessarily. So if you are not on this particular UNIX or Linux build you could certainly add it to your system relatively easily. Install is painless takes five seconds - you can go ahead and run that. So we will clear the screen now let us go into compiling our simple program. So if I list what is in here you can see that I have a cybrary.c - so we are going to do a gcc or enter the name of our source code. So it is cybrary.c and then our output which is whatever the name of the executable that you want us to be named. We will just do it - we will be simple and choosy here. We call it Cybrary and if you don't get any errors - things went pretty well. So that is it we have written some code - we have just compiled some code. Pretty simple next part we could actually run the code. So do a ./ and then the name of your program and hit enter. cybrary.it is cool which is the print statement that we had in our document and that is the absolute basics to one getting some c code in a file. Again very, very simple you can build upon this - next you can start putting in memory allocation and start setting parameters or start manipulating this file and build upon it. Which we will do in subsequent videos to try to get it to do something cooler than printing something to the terminal. So what we have done is written some c code and compiled it and then executed it and you can see it was relatively easy to do. So a little knowledge on c programming - you can certainly easily just create some generic code. Now when the next couple of videos will start looking at input statements and memory allocations and things like that and start looking at how basically make this program do bad stuff. So that is it my name is Leo Dregier - thank you for watching and don't forget to check us out on Facebook or LinkedIn YouTube and Twitter. [/toggle_content]
Recommended Study Material
Learn on the go.
The app designed for the modern cyber security professional.
Get it on Google Play Get it on the App Store

Our Revolution

We believe Cyber Security training should be free, for everyone, FOREVER. Everyone, everywhere, deserves the OPPORTUNITY to learn, begin and grow a career in this fascinating field. Therefore, Cybrary is a free community where people, companies and training come together to give everyone the ability to collaborate in an open source way that is revolutionizing the cyber security educational experience.

Cybrary On The Go

Get the Cybrary app for Android for online and offline viewing of our lessons.

Get it on Google Play
 

Support Cybrary

Donate Here to Get This Month's Donor Badge

 
Skip to toolbar

We recommend always using caution when following any link

Are you sure you want to continue?

Continue
Cancel