Custom C | Library Functions In C | Adding Custom Function To Library | Creating Library | Functions : Part 5


Subscribe Here





Library Functions In C | Adding Custom Function To Library | Creating Library | Functions : Part 5


Hello, guys! I hope you are all doing well in this video. We are going to talk about library function. We will also talk about how we can add our custom functions to the pre-existing library files, and at the end we will talk about how we can create our own personal library files, so let’s begin. [MUSIC] A library file has pre-compiled code of implementation of our functions, right, so there are various libraries present. For example, there are studio library, maths, library and other libraries Also. Okay, now, let’s say I want to add this function definition to our existing library, okay. The definition of this function should be including our in our existing library. Now, first of all, we will create a file and give it some name. Okay, let’s say the name is fact. Dot C. Right, then I will write the definition of our function. Okay, so here it is written the definition of our factorial function, right, it calculate the factorial of the given number here and written as the final value. Okay, after that, what I will do, I will compile this code, okay. After compilation, it will create a file with the name fact Dot Obj note that I have not written any mean function here and also no prototype is given here after that we will use a utility of Turbo C compiler, which is the t-lib, which is used to manipulate our library files. Now in the command line, What I will write Tlip, Then the existing library. Let’s say the library is maths dot layer And what I want to do. I want to add the object code of this file of to this file, right, then I will write here Plus since we are adding the contents, then the name of this file, which is fact Dot Obj now. The object code for this file has been included to our maps library, right note that this is According to the Turbo C Compilers different compilers uses the different functionality to add object file to the existing libraries. Okay, so this is according to the Turbo compiler. Now our code. Our compiled code has been added to, uh, to this library, right, so the definition is now present in the maths library, And now I have to also write its prototype for prototype. I will create another file. Let’s say the name of the file is fact Dot H right and inside it, I’ll write the prototype something like this, in fact, and inside it integer, that’s all okay. So prototype is defined in this file, and the definition is compiled and added to the math slab theory. Okay, now, let’s say I want to use this functionality. What will I do? I will create a file a simple program file. Let’s say ABC Dot C. Then I’ll write hash include Studioh and then hash include now which header file? I should include fact. DOT H. Okay, fact, DOT H. Why because we will be using the fact function later in the program, so we have to include its prototype and the prototype is written in the facth header file. Okay, note that here. I am using double quotes. Why because this is the custom header file, okay. The standard header files are written in these less than and greater than symbol and the custom header files are written in the double quotes. Okay, we can also specify path here. Let’s say spa something could be like C inside. There could be fact Dot. H Then I’ll write here. Just be doing simple programming. Word mean now I will write int a variable. Let’s say the name of our variable is num. Okay, and then let’s say I want to find the factorial of 5 Then what I will do. NUM equals to fact 5 right, and then, after that, I will write here Printf of person. D and then num. [MUSIC] Okay, that’s all so the prototype of our function is defined in this file, right, and we are calling it from here. After the compilation of this file. Another file with the name ABC Dot object is created. Okay, the extension may vary, according to the compiler, right, and what will happen after that our linker will link all the library files and then create a executable file. Okay, so when it is linking, it will also link our maths Dot Lib file, okay, which has the definition of our fact function. Okay, and then after that, we execute this program right, and when we will execute this program on that particular time, we will also have the prototype it’s calling, and its definition, right, and then it will give us output as the 120 According to this line, okay, so basically, this function has become now our library function library function because the definition of this function is residing now in one of the libraries. Okay, now another resemblance. You can see here that we are using printf. Yeah, and Printf is also a library function library function. Okay, why because the definition is already present in the studio library studio Dot Lib Okay. And inside Studioh file. The prototype of the Printf function is written. Okay, that is why we are including these header files because the prototype of any function is written here. Okay, so here is the prototype. Here we are calling. And the definition is written inside the library files. This code is already compiled. We don’t need to compile it again and this only this amount of code we are compiling. Okay, and Linker is then combining all those library files and the object files and creating an executable files right so. I hope you are getting the idea what’s going on. Now, Let’s try to create our own personal library file. Now, let’s say I want to create a library files with the name Factlib. Okay, I want to create a library file with the name factlibrary. Okay, first of all, we will create a file with the name factc. Okay, inside it. We will write the definition of the function, which we want to include in our library files. Okay, I had used here only one function, but we can also include the other functions also. Okay, we can write the definition of prime numbers and Fibonacci series and right inside this file. Okay, fact, DOT C. I am using only one function here just for the better explanation, so we create a file with the name factc inside the it. I’ll write the definition of all the functions, which I want and note that I am not using here Main function. Okay, only the content this content is written after that in Turbo C. We will go to the option menu. Okay, inside the option, there will come another option of application. We will click on there and then we will select library and then we will click on OK, OK? That means that after the compilation, the file will, which will be created will have the extension of Dot clip or a library file will be created note that this is according to the Turbo C and C plus compiler and different compiler, use the different functionality or different way of doing this. Okay, after clicking, OK? I will compile this file and after compiling, it will give me name as fact Dot Lib. Okay, a library file will be created here, so the definition of our fact function in the compiled format will be written in the fact Dot Lib file. Okay, so the definition is present here now. We will also have to make a prototype for prototype. I will create a file with the name facth and inside it. I will write the prototype for this function, okay. If you are using multiple functions here, then you have to write the prototype of multiple functions here. Also, okay, so here is the prototype and here is the definition. Now, let’s see how I can use it so here. Let’s say the name of our file. Normal file is ABCC Then I will include our files that say Studioh. Then I will include also my custom header file. Which is the facth? I will write here Fact. Dot H. Right, then void mean right here. Let’s say Printf percent D and I’ll call this function fact with the value. Let’s say 5 right, and that’s all now after I compile this. A file will be created as ABC Dot Obj, which we generally don’t care about much and then our linker, which is a part of our entire build process of a program, will link all these files. Okay, so it will link ABC DOT OBJ and also link the fact Dot Lib file, okay, and other required library and object file, okay, it is a role of the linker to link all the library and object files and create a binary formatted executable file so here. The name of our file is abc dot exe. Abcexe file will be generated after the Linker. Okay, so the prototype is written in Facth. Here we are calling our function and the definition are present in this library. Fact, Dot Lib and everything is linked by our linker and then an executable file is created with the name ABC, which is the name of our current file. Okay, so this is how we are able to create a custom library. So that’s all for today, guys. I hope you like the video. If you have any doubt, please comment it down. Thanks for watching, and I hope to see in the next video.

0.3.0 | Wor Build 0.3.0 Installation Guide

Transcript: [MUSIC] Okay, so in this video? I want to take a look at the new windows on Raspberry Pi build 0.3.0 and this is the latest version. It's just been released today and this version you have to build by yourself. You have to get your own whim, and then you...

read more