 Hey everybody, this is Brian and welcome to the 99th Qt tutorial with C++ and GUI programming. I'm going to have to apologize in advance, my voice sounds a little weird, I'm actually home sick today. But we're not going to let that stop us, I'm the type of person that just can't sit still so I figured we do the 99th video, getting closer to that 100 mark. So today we're going to do static linking and static compilation. What is static? We've talked about static compilation before with an EXE, but we're going to do this from the context of a library. We've talked about a dynamic link library, a dynamic link library means you can dynamically add that later. What we're going to do is do a static library. You notice how when you choose a C++ library it gives you the option of a shared or a dynamic which can be used with Q plug-in loader or a static and we're going to do static. Choose and see if we choose static library. Let's call this statlib, put this in the usual location and just next, next, next. Now you notice how in our config file it says staticlib, that right there tells you that it's going to compile this statically. Go ahead and give this a good build. All right. Now let's open up our target here. You see how we have a libstatlib.a and then a .o, well that a file right there and it may be different on different operating systems, but in Windows that right there is the binary that just got compiled. If you go to debug I don't have anything in there so we're in release mode. Now what we're going to do is we're going to actually use this. Let's go file new and let's see here. Let's just make a console application and we'll call this stattest. I'm sorry if you can hear my cats in the background meowing. I had to lock them out or they'd be in here bugging the heck out of me. Last thing I want is a cranky pants and catzilla in here bugging me while I'm trying to do this. So now we've got our just simple test app and let's give this thing a good whirl. Now, nothing special about this app, it's just a normal console application that we've done before. What we're going to do now is we are going to modify this project file to include various aspects of this. So let's jump out here and the first thing we want to do is get our header file statlib.h. So let's just copy the path. Now what we need to do is very simple. We need to give it the include path and the headers. So let's see here we'll say include path. Now we're going to want to switch these to a more cross-platform style. I know it's kind of a mizomer by being on windows and then switching it to a cross-platform style. It just helps cute a little bit. And then we want to grab that lib location. We want the a file. We're just going to say libs and let's just fix these up real quick here. I've been working on the 100th tutorial. It's actually going to be a fairly large one with a lot of detail. So thank you for kind of sticking around here. Let me pause the video real quick. Sorry about that. One of the convicts was breaking loose. All right. So we're going to add an existing file. And we just want to add that header statlib. And we did make a boo boo here with the include path. We don't want the h. We just want that. There we go. So real quickly what we've done is we've said include path and we've given it the path to where our headers are going to be. And we've given it a lib path. So we're actually linking to a library here. And this is the a file. And then when we added the header, it went ahead and added statlib.h. Save that. Let it reanalyze the project here. There it goes. And then let's give it a good build. Make sure it builds correctly. And you see we have no build problems. So from this point what we can actually do here is start including. Give it another build just to make sure everything goes good. Now you may be wondering what's the big deal here? What's going on? Well, the thing is very simple. We've got our library right here statlib. And it generated that binary, the a file. That code is being statically compiled into our program. So we don't have to include a dynamic link library. To kind of prove that, let's just go in here and let's make a test function. And then let's just add a include. We'll add Qtabug in here real quick. And then let's say, wait, you can tell I'm kind of rusty at these, I haven't done a video in a while. For that I apologize. All right, we'll say Qtabug a little from the static library. We'll just say static lib for the sake of time here. So we've got this code that exists in our library. Let's actually give our library a good build here. Oh. For bids, declaration of test with no type. Oh, yes. Told you it's been a while since I've done a video. There we go. So we've got a good build here. Now if we jump into our code here for our project, we need to say statlib. And let's just say, clib and let's call test, compile and run. And you see when it runs, it says hello from static lib. Now you're probably sitting here going, I don't understand what's the big deal here. Well, in dynamic link libraries, you would have to distribute this application plus the DLL. And with a static linking or static library, it's included inside of the executable. So all you have to do is distribute this exe. The library is already included in there. So when you go to, let's say you're the library author, you want to distribute this. You just simply give them the header file and that a file that we talked about earlier. Let's see if we can jump back out and find that. This guy, libstatlib.a, the binary file. So they don't actually see your code. You can have a bunch of proprietary code in here in the implementation file, but that's already compiled into a binary. So you just give them the binary implementation and the header, and they can statically link it into their application. Let's offer this tutorial. Like I said, I got to apologize. It's been so long. So I've done one of these. I've just been really busy with life and work and everything else. But the 100th video is coming soon. I promise. All right. Talk to you later.