 Hey everybody, this is Brian. Welcome to our 98th Qt tutorial. We're going to continue our conversation on DLLs. Make other and a Qt console application. And we'll call this LibTester. We're going to use that library we created in our last tutorial. Throw in the usual location here. Next, next, next. Now you notice how I have two projects open. Probably some of you have done this before and some of you haven't. You can have multiple projects open in Qt Creator at the same time. Notice this is in bold, LibTester. That means it's our default or active project. You can switch that just by clicking something else and setting active project. So let's make sure LibTester is our active project. And this is just a console application. And what we're going to be doing is using this DLL which we created in our last tutorial. But I will include the source code and the actual compiled DLLs with the code up on my website just in case you're just now tuning in. So we've created our DLL and we've covered these beautiful little header files and what they mean. And our code is very simply just has a test function. We're just showing you the concept here. And test just has a Qt debug that says hello from our DLL. And we've already compiled these. So what we're going to do is jump in here and we're going to include our header files. Now before we can do that we need to actually include them in our project. So let me pause this. Remember when we created our DLLs it created these header files. We need both these header files so we'll copy these. And we're just going to put them in the same directory with our current project LibTester. There is a way to link these through Qt Creator but just for the sake of time and understanding we're just going to do it this way. And then we are going to add existing files LibTester. And we're going to select our headers. Now they're in our project here. And we're just going to include mylibh. Now we have access to our DLL. Now we've got a header and we've included it. So if we just try to give this a good build and let's switch this into debug mode. Whoops, debug mode. Third time's a charm, debug mode. There we go. We switch that into debug mode and then just give this a good build. Notice there's no build issues. We got a good compile output. But if we try to run this, let's try to run this and see what happens here. Everything works fine. Now let's say mylib, we'll just call it clib, and we're going to call our test function. This is a common pitfall most people fall for. Notice how our first one said exited with code zero? That means nothing bad happened. Let's try this again. Notice how there is a whole bunch of undefined reference to and then there's these weird symbols. What could these possibly mean? See how it says exit one for status. Well what that means is it's missing that DLL. It can't find the internal symbols for that DLL. So you need to take the DLL and put it in a place where your application can find it. So let's just back up here. Go here, debug. Because we're in debug mode, we want the debug DLL. And here's our lib tester. There we go. And let's just jump back out here, get our release version of that, and copy and paste the release version out here. We're doing this because this is where the actual ex is going to be created and launched from. So if the DLL's there, it'll be able to find it. So let's try this again. Did not like that. What did we do wrong here? Oh yes. We forgot to actually include it. Now looking at our project file, you see that something's missing. Qt doesn't know where the actual library is. It doesn't know what to link to. So it's complaining undefined reference to. We haven't defined where these are. So it's looking for that code from the header file. So what we're going to do is we're just going to type libz plus equal. And then we have to give it a path. And let's kind of cheat it and copy and paste it here. Here is the actual full path of that DLL that it's going to link against. It does this because this is called static binding or I'm sorry not static binding. This is where it links to it. And it does that because every time you build a DLL, it might be slightly different. So mylib.dll that I build is going to be slightly different than mylib.dll that you build. It's the difference between the compiler, the processor. I mean all these things come together. I know a couple of you gurus out there going to send me hate mail and I appreciate your feedback. I would love a better explanation because I've actually struggled with this myself for quite a long time of how to accurately describe this. Anyways now that we've got this, we can run this. And you see sure enough it compiles it runs and it says hello from our DLL. Let's jump back into the code here and let's really explain what's going on here. We've got our lib tester which is just a basic little application. It's just a command line application. And inside there we're telling it libs plus equal and we're giving it the path of the library. We've also given it the headers to the library so we know what to expect. And of course we need to know the exports of that library too. Now in our application we're just including my lib.h which we created down here when we made our actual DLL. And then we're creating an instance of our class and calling test. If any one of those little things don't line up you're going to get a compiler error and you get all sorts of linker errors and it'll complain and grunt and groan and you'll have all sorts of little gremlins in your program and it just flat out won't run. And if it does it won't run for long and it won't run very well. So you need to always check that all these things line up. But that in a short version is how you use a DLL. This is Brian. Thank you for watching. I hope you found this tutorial educational and entertaining.