 Hello, good afternoon all of you, I am Prajakta Patil, I am working as a CISAR in CAC department and student of MTech 2 second year. Now, today I am going to cover the main topics that is introduction to Linux environment and GCC. We will see the agenda, now introduction to Linux environment all of you must be aware of the windows environment and we will look at the Linux thing, we will look at some text editors that is V, VIM and G edit, we will write some programs in these text editors and compile them with either GCC or G plus plus. Now, you must be watching the login screen on your computer, I guess all of you must have logged in into the system, as here it is saying that we are assuming no Linux background from all of you, so be relax, now we have to start the terminal I hope you all of you logged in in the system. So, we have to start the terminal, now what is the terminal? It is a common box through which we can execute some commands, we can through the commands to the operating system, we can launch the applications or we may execute some programs. For example, in the windows system when we double click on some windows media player it gets started, same here if we type some command the application get launched. Now, you can go to the terminal through application, then accessories and terminal, you can go to the application that you can see on the left corner in that accessories and that terminal, you will see a white box or there are other ways for opening this, you can also do ALT F2 and can type genome terminal the same box will get open, ALT F2 will open some will pop up a small box in that you can type genome dash terminal G N O M E genome dash terminal the same white box will get open, so through this terminal we will write the code. Now, when you open the terminal you can see a prompt which is displayed on the terminal the prompt is made up of some word followed by add sign followed by some again word and colon tilde and dollar sign. Now, dollar sign is nothing but a prompt, now the word which is word before add is your user name is the same user name which using which you have logged in, after add sign you can see the machine name the machine which you are using and after that the tilde is your home directory, the Linux is made up of a directory like a structure, there is a root directory the main directory inside it has a home and inside all home directories of all users is are maintained. Now, you are currently logged in to the home directory of the user you are logged in, now you have to work in that home directory only, so now we have to create one directory inside your home directory. Now, you must be aware of the folder structure of the windows where you can store many files for example, if you want to store the files of say movies and songs, you create separate folders for movies and songs, the same structure maintained in the Linux, you can create the directory using command mkdir that is a simple simplest command mkdir is nothing but Mac directory, the syntax is mkdir the directory name, you can create the name you can specify may be your own name mkdir and directory name. Now, after executing mkdir you on the prompt you are on the same space or the same position on which you are before executing the command. Now, you are currently working directory is home slash home slash user. Now, you have you want to go inside the directory which you have created right now, you can use the command cd and directory name, cd is nothing but a change directory, change directory and the directory name the same directory name which you have created right now, so now inside you are inside your directory. Now, you will store all files or programs which you will write today. Now, here are some basic Unix commands which you will require for running the Unix system. Now, ls is listing the files in your directory, currently if you type ls in the current directory it will show nothing because you have not created any of the files in the current directory. Now, pwd is displays the present working directory, if you type pwd it is showing the directory slash home slash user and pure directory. Cd we have just shown we have just done right now that is a change directory, remove it is removing a file nothing but deleting a file from the folder. Now, copy is a cp is copying a file then move or mv is a moving a file that is nothing but a cut paste in the what in the windows we do mkdir we have just rmdir is nothing but a removing a directory. These are the simple commands for the linux. Now, we want to write a c program for writing a c program we can use the different editors and I have also created the directory I am going inside the directory. Now, we will write the program using text editors. There are different text editors maintained with the unix environment. We look at the vi and g edit. Now, vi is very powerful text editor. Now, for using vi we have to create one file that we can create using vi. You can use also vi, vi is the latest version, vim set temp dot txt. You will enter in the vi editor there you can there are actually two modes two working modes of the vi the normal or command mode or a text mode. In normal mode the key strokes the key which you are you are pressing are nothing but the commands you are giving to the vi editor and in the text mode these are the simple letters you want to type. You can enter into the command mode by typing the i you will enter into the insert mode. There you can type anything if you want to save the file you have to come again back from the insert mode by pressing escape and if you want to save then colon wq enter. It exits from the vi by say after saving the file if you do not want to save the file just colon q enter. If you want to see the view the file you have just written right now you can say cat temp dot txt. This is the same file it is displaying the same file on the console that we have written right now. Now, again I will open the file first you will find it little bit difficult while working with this editor but after practicing you will find this is very great. Now, I will write some lines over here. Now, the various commands you will see for deleting you have now you want to enter some commands. So, come out of the insert mode. So, that is a command mode if you go on some line the green cursor is showing the line which I am highlighting. If you press double d it will delete the line currently my cursor is on the first line. If I press double d then it deletes the line the cursor the line which cursor is highlighting. Now, in this editor they have they have given the facilities you can move here and there using the arrow keys which are provided on the keyboard. Previously you have to use different commands for doing this but you can use the arrow keys which are on the keyboard for moving up and down. If you want to search a particular word you can do you can you have to come again out of the insert mode and press slash look at the down is it visible. Now, if I want to search for a word I will press I will come out of the insert mode I will press slash and I will put the word which I want to search enter it will highlight the word it will go at the start of the word where it found the word. And if you want to go to the particular line you can do this by colon and a line number in the say in any integer it will go to the line number. You can study other command from the VI on this links it is very the first link is very useful it gives almost all commands which you can run on VI. G edit is another GUI best editor this you will find little bit easy because it has the same structure same as I mean what you will use what you use in the notepad in the windows structure. So, you can open the g edit g edit and file name and you will do anything on g edit and file name it will open a notepad like structure and there you can do anything like search and replace then editing cut copy paste it can displace the line numbers also when you write programs in different languages it also highlight the syntax various syntax you can directly have a print option in the file menu then I said the search and replace then bracket matching I will think if this GUI editor is available then why to use this VI-VM because sometimes what happens the machine we get is just has the command mode and not the GUI mode in that case also you can use VI and edit all files all system files that you want to edit even if the GUI is not present VI and VI-M use VI or VI-M can suffice I will go to the actual now we are very comfortable with the Linux environment and the terminal and editors now we will use this editors for writing the C programs now GCC is nothing but GNU compiler collection which is a compiler system the developed by GNU project it is used to compile the programs written in different programming languages now here is the first program that is program 1 dot C now you can write this the same program using VI-M just we have seen VI-M program 1 dot C you can type the whole program it is a very simple program it is just declaring one variable printing hello VIM iterating through the loop and printing the various integers and finally done you can write this program in one file and save this file using colon WQ you have to install one software using apt gate I will write here on one just type one command sudo apt gate install build essential this is for running the program through GCC just type this it will ask for a password enter 1 2 3 now this is the same program now I want to compile this program using GCC compiler I will use the command GCC program 4 dot C if the program is perfectly written that is no syntax error or no any logical error then it will come out of the command at it shows it shows the prompt that is the compilation is successful no errors after compiling it creates one executable file that is dot out file named as a dot out which you can run as a dot slash a dot out which displays the output actual output of the program which is expected if the compilation is successful then only you can execute this step dot slash a dot out by default it gives the name a to the executable file you have if you want to give the different name then there is a second command you can GCC program 4 dot C you can specify minus O option and say program 4 it is the name that you want to give to the executable file and you can run at run as program 4 if you want to give some different name to the executable file you can give it through minus O option now there are some other options for the compilation using GCC you can compile a different source files using GCC and specifying the least of the source files that you want to compile but here it without specifying any other option it links those all files together and it creates a simple one executable file. So, if you have the different files say P1 dot C P2 dot C and if you have main in both the files then it will not execute successfully because it tries to link both the files creating a single output file I have one example which is not with you I will just show you the thing this is one program that is program 1 dot C it may not be with you here the last second last line it is calling print hello function which is not declared which is declared in the same file but not defined in the same file the print hello function you cannot see the print hello definition the definition of this function in the same dot C file I have declared I have defined it in another file here it is just returning or printing goodbye now I will compile both the programs together so that GCC will link them together and it creates a single output file combining both these source files. So, it prints everything and the last function call for printing goodbye it goes to the that file prints and again come back. So, it is nothing but linking two files using GCC you can enter the debug mode using minus you option there are different debug as present you can see it in the later presentation if you want all warnings to be displayed on the screen after compilation you can give the option save minus wall it displays all warning options in the previous example we have seen that it links all the files together if you do not want this to be happen that if you want the different absolutely different files which I have to be compiled together you have to specify option minus C after that all the C files will get compiled and it forms the dot O files dot O files are nothing but object files and these are simple binary files which these cannot be executed this again have to be converted into executable files using GCC now these are options you can write various large programs and can I mean if you have very large program then you can divide it into two simple small programs you can link them together you can debug through minus you options and the C programming becomes very easy using GCC now this is another example that is dot CPP that is C plus plus exam the currently above it is showing IO stream it is the same it is header file used in C plus plus using name space sd it is you can say it is a package or a group of variables or maybe definitions that are defined that are defined in sd library if you do not specify this using name space sd the C out and C in all these operators are defined in this sd and every time you have to specify sd double colon C out sd double colon C in so when you specify this using name space sd above the compiler itself search for all this C out and C in the sd library and you will not have to enter it again and again you can create your own name space also and use in the program now what it is doing it is just defining a constant and taking one taking the radius of a circle and calculating area that is nothing but a pi r square and displaying the same you can also write this program in the vi editor currently I have it but GCC it will give I have program 2 dot CPP that is a C plus plus file the same file that we have in your presentation I am compiling it with GCC compiler it will give errors because GCC does not know thus header files or any other library is required for compiling C plus plus program. So, GCC provides the generalized structure it has G plus plus sorry for compiling the C plus plus program I am just typing G plus plus program 2 dot CPP it is it creates the same dot a dot output file the other options and other things are same as GCC and you can type a dot out it ask for the radius I will put set 20 and it displays the area of a circle that is pi r square. So, GCC for different languages it provides the different set of the compilers that you can use very easily the structure remains the same you can use in a different languages the other things that if you want to change the a dot out file then the same option minus O option linking you can you can also link the files you can also go into the debug mode for debugging some other interesting thing is some libraries have to be enabled while running the program for example, thread dot CPP it has it requires the LP the P thread library for running the same program. So, it can be run as follows G plus plus threads dot CPP minus LP thread because it executes or it has some thread system calls for that it requires this system library.