 So far we've been working with just a single executable and life's been well pretty simple But there's a whole chain of technologies under the hood that we haven't really talked about So what really happens when we build our executable is well, there's pre-processing compilation and then linking and This graphic is just beautiful because it really summarizes what happens You have a pre-processor that goes through looks at your headers and source and figures out what really needs to happen You have the compiler that takes all of that and compiles it into what are called object files These object files are then run through what's called a linker, which creates your actual executable the thing that you're actually running But it gets even more in-depth. So this executable does not live in its own little universe So let's say this is your executable. It can use multiple libraries and these libraries can use other libraries So what are really libraries? Well libraries are just a collection of code that don't directly execute themselves, but they can be called by executables So this is where the term code reuse comes in Let's say you have this really awesome class called cat and the cat does this cool thing called meow And you want other programs and other programmers across the world to use your code You just simply put it in a library give them instructions on how to use it and they can add it to their program And they can make the cat meow all day long This graphics beautiful Really summarizes what I'm talking about. This is called dependency walker and exists on windows Don't worry. You don't need windows to follow along, but this is just a really good graphic So you have your stuges.exe and then you have your Larry Curley and Moe DLLs or dynamic link libraries they're called libraries or system objects or Libs depending on your operating system, but basically you have an executable and it depends on certain libraries Some of these libraries like kernel 32 are already built into your operating system But it's still needed for your application to run and if something's missing for example, you see how Curly's in red Well, it's not going to run and we'll demonstrate that But you should also understand there's multiple ways of doing this as well. That's right. Life in programming is never simple So there exists the concept of a static build versus a shared build So static is you take all those libraries that we talked about and you put them into the executable So you just have one giant and I do mean giant binary file that you hand the end user and you may be thinking well That's very convenient and I love that. However It comes with some complexity. It comes with some cost and well, you could really run into some issues Some of those issues would be legal. For example, you would be breaking license terms and agreements things of that nature Other technologies just simply won't work because they're expecting to be in a shared format shared has a much smaller footprint a much smaller deployment, especially when you go into multiple applications and Multiple applications can use the same code base. So as this is updated multiple applications can take advantage of that The problem with shared though is if you change this and it has some breaking fixture, you're not just risking breaking one application, but multiple That's complex. So take let's take a look at an example here We're going to create a new other subters project and let's call this cute To Corvance 3 1 and we're just going to finish it immediately It's going to say what do you want to add to this and I'm actually going to close out of that and just show you the project file Just simply says template subters. So there's absolutely nothing in this We're just going to add a new subter project go to application add a console application. Let's call this my app Next next finish and it's just going to generate a bare bones application that we've done dozens and dozens of times See tada So you may be thinking that this is something new, but actually when we've worked with say network and concurrent and we've some We've done this Really what we're doing under the hood is we're adding the network library. That's just cute ways of doing Built-in cute libraries. We're going to make our own library and actually put it into this application So let's go ahead right click and let's add a new sub project Let's go to library and we really only have one option C++ library But notice it says shared or static remember shared self-explanatory It can be used across multiple applications shared or static is a little bit confusing because Shared means that it can be shared static means it's built into the executable So We're going to do shared but you could also do statically linked or a cute plug-in Plug-ins a different topic. We're also going to cover and basically what it means is you can dynamically use that library across Different applications as long as it follows a specific interface So we're going to do shared. Let's call this my lib All right now select required modules modules. What does that mean? Well, remember? Network we added it up here. So really these are just libraries. That's right. Qt is sectioned off into libraries So Qt itself really isn't an executable Qt is well a series of libraries and we've been using Qt core this whole time We've also worked with network and concurrency. So when in doubt, we're just going to leave Qt core hit next and Finally something we're familiar with classes. So this is going to create a class called my lib with a header and a source file Next next finish and then it'll take just a moment But now we have this beautiful subters project that has two subdirectories the application and the library The app of course has its own project file and notice how it's a console application where the library well Template equals lib. So this is not a direct executable Although it has code that we can execute. We're not going to execute this directly. The library has to be called from an application So let's look at the structure of our library real quick. It contains a global file and a header file Notice they're both really headers So if we crack open this global, it's got some preprocessor directives We've got a defining here. So if defined my lib underscore library, then we're going to export Otherwise we're going to import. So what's the difference here? These are called symbols You need to export symbols and it sounds really complex. But what's going on under the hood is we're basically saying When we export what we export is available to the application And we're getting this my shared lib Right here. So class and then we're declaring my lib shared underscore export my lips So this whole class is going to be exported Which basically means Everything this class has that's public is available to the outside world Now we're gonna say Actually, let me change my rhythm here We're gonna add Q to bug our trusty friend that's been with us since the beginning And we're gonna make a very very simple function here Don't want to get mired in complexity on coding. We just want to understand the core concepts here I'm gonna do something we've done a hundred times This is a test from my lib. Hope if we spell from correctly so you notice right off the bat that my lib includes my global and Under the hood. Well, we've got some other complexity going on. We have an export and an import the export is saying hey Export these symbols Meaning export this class so other things can use it the import is saying hey import this class so that we can use it It's a little kind of tricky to wrap your head around until we do this What we want to do is make this library available to this program So we're gonna right click. We're going to add library and notice right off the bat We have some choices internal external system or package So internal library means it's internal to our project external means it's outside of our project and System means it belongs on the system. It's probably already installed system packages very similar, but much much more complex So we're gonna do internal because we want to import this my lib because it's in our project And we get this drop down. That's right. You can have multiple of these Choose what platforms you want and then we have some platform specific features For example Matt can be a library framework that gets into a whole separate topic. Just leave it as default and windows We can set up a special, you know, directory structure here We're just gonna leave everything as default make sure my lib is selected Next and then we get some stuff that makes no sense, but we're gonna talk about it So really what's happening here is in our applications project file It added a few lines and it's just literally saying when 32 configs So windows config release do this windows config debug do this Else if it's not windows do this instead All right, so what's going on here is actually kind of confusing. So you see how it says libs plus equals So basically we're adding a library plus equal The uppercase l Denotes that this is the path that we're going to use whenever you see dollar dollar inside of a project file We're basically declaring a variable. So dollar dollar Output so we're gonna output the print working directory. That's a little confusing, but basically we're saying Specifies the full path leading to the directory where Q make places the generated make file Places the generated make file meaning the compile directory where this executable is actually going So we want to go up a parent and then we're going to the my lib folder and then the release version Because this is release or if it's debug we're doing the debug The under or I'm sorry the dash lowercase l the under I don't know where I got that from Lowercase l. This is the actual file name. So really looking at this seems a lot less confusing. We're saying Take your platform take your configuration Whatever that may be whether it's release or debug Then add your library the library's path is This the library file name is this All right, then you have include path and depend path and this is a little bit confusing But think of it in terms of this is when compilation happens it needs to know what we want to include and this is after it's been compiled and you want to run it where we actually looking for that library and Really that gets really confusing out on forums a lot of people get it confused and I myself have gotten a confused numerous times and Sometimes it literally will make no sense. You'll compile and nothing happens the way you suspect Go ahead and save all now just a double check. We've got that in there Nothing's really changed in here. We should be good to go and We're gonna just go in here and let's go ahead and add some files So we're going to include and we want to Go up a notch go to my lib and we want to add the my lib global because we want to import If you skip this step, you won't be able to use it because what we're doing here is we're saying if define my lib Which in this project is not defined Then we want to import The my lib shared so we're basically saying import. Ta-da this guy this whole class Let's jump back here and Let's actually import that class now And we're gonna say my lib test. So we're actually calling the test function in my lib This guy here, but we're calling it in our application now comes the critical part. We're just going to build everything Notice how right off the bat cannot find and it says Lowercase l my lib now because lowercase we know that means that's the name so it can't actually find it We'll go out to our folder and sure enough there it is. So why can't it find it? What's going on here? Sometimes it gets a little confused So what I'd recommend if you jump into this problem, you just rebuild your library Make sure you got a good build now Rebuild your application and voila suddenly it finds it And you can actually now build this and everything just works And let's make some minor change That way it knows that this file is changed and we need to rebuild this. So let's go ahead and build this and Ta-da just works. So if you ever get one of those can't find blah blah blah Try rebuilding your library and then try rebuilding your application and do those separately Sometimes Qt creators not that friendly when it does that Now we should have this beautiful my app file sitting out here Let's go ahead and run this Ta-da, this is a test for my lib. So the application is actually calling the function in the library Pretty sweet Now if we go out here And we open this guy up And I just want to see the dependencies what's going on here You can see we've got a lot of dependencies here But we also have a problem not found and it's of course my lib Dot so dot one not found there's numerous ways to fix this But what's really going on under the hood is this is an operating system problem not a cute problem And if we try to run this application We're gonna get a big fat error. Let me actually Do that again My app error while loading shared library my lib Not found meaning same problem. We had before where it's just not finding the library. This will drive you insane Some operating systems you can actually just copy and paste the library directly into the same app same directory as your application We can try that but I'm not convinced it's gonna really work So let's go back in here and let's go to my app paste this And let's do Same thing not found. I'm very confident that if I try to run this it's not going to work So what's going on under the hood is what's called a search order or a search path and every operating system is a little bit Different windows you probably could get away with just throwing the the DLLs in the same folder But you would look for what's called a path and we're gonna echo out Our path here and this is the search order for this computer and you can see it's looking in user local S been user local been so I would put it there But the problem is I may not actually have well permission to write there And if I don't then it becomes a chicken or the egg problem. How do I get the library somewhere where it can find it? This is where you really deep dive into your operating systems documentation. So because I'm on Linux I'm gonna use what's called an LD. So I'm gonna say LD library path which basically says hey we're going to Modify the path search order here just this one time I'm gonna say my lib and we want to run it in my app So what we're doing here is we're saying LD set the library path to my lib meaning the current directory Subfolder my lib and we're gonna run my app. So I need to actually Let's grab these Shove them right in there. So now they're in this subfolder and let's run it Ta-da, this is a test from my lib. So that's a very frustrating problem You're gonna really get stuck with and this is why you would need a deployment structure or a setup program of some type Which we'll cover in a future tutorial But I want you to be aware of this problem now in case you get really excited to make an app and then it just Doesn't work. So when in doubt when you're missing something check your search order Check your documentation for your operating system and know that LD library path is widely used on Linux But it's not the most recommended way Let's just face it cute is extremely complex and has a massive learning curve But once you learn it you can do just about anything Unfortunately learning cute is a challenge in itself and if you've tried learning straight from the docs You've probably become easily frustrated while they do a really good job They're arguably some of the best documentation in the world. They don't go that extra step and leave a lot of people guessing what to do How do all these things interconnect? That's why I started developing videos. I've done videos not just on my own YouTube channel Which you're watching now, but also on the official cute studios channel and I've started doing video courses out on you to me Com right now. I have the cute core series. It covers beginners intermediate advanced So it'll take you straight from hello world all the way up to building a complex Multi-threaded encrypted TCP server on top of that if you don't want any of this You can still join the void room's Facebook group which has a pretty flourishing group of developers and we discuss everything not just cute I hope to see you there