‫Hello and welcome.
‫In this lecture, we're going to be understanding the main steps involved in compiling C++ files in
‫Unreal.
‫Let's dive in and see how they work.
‫So it's soon going to be time for us to start using code from the outside, from other files, and we
‫need to learn how this works in C++.
‫To do that, we need to take a little bit of a detour and understand in more detail what's going on
‫when we compile our C++ code into binary.
‫So here are the compilation steps that are used.
‫We start off with your code, your C++ files, your header files, all in various text files.
‫These get fed into a tool called the Unreal Header Tool.
‫Now, this tool is responsible for taking all the unreal specific pieces of syntax and using them to
‫generate more C++ code.
‫So let's have a look at some examples of where we've got this unreal specific syntax, this new class
‫in capital letters that is unreal specific syntax, and so is the Crypt Reader API thing here and the
‫generated body there.
‫And basically what's going on here is the unreal header tool will see these different pieces of syntax
‫in your code and go, okay, I need to do my job.
‫I need to go in there, I need to add a bunch of stuff.
‫It's going to replace your generated body with a bunch of code that makes our lives easier when using
‫Unreal.
‫It's also does things like the U properties and new functions.
‫It adds all the stuff that it needs so that it can communicate with the blueprint world.
‫So that is the first step.
‫It converts all of its unreal specific stuff into actual C++.
‫Once we've got the actual C++, we can then feed it into a standard C++ compilation process, which
‫takes three steps.
‫The first is to deal with the preprocessing step so this can actually touch any of the C++ syntax and
‫actually only deals with lines that start with a hash.
‫So we've got a few of these preprocessing directives.
‫These are dealt with by the preprocessor.
‫The next step is what we actually call the compiler.
‫It takes a code and it converts it into executable binary, but it doesn't quite complete the step because
‫it only does it on individual C++, what are known as translation units, basically C++ files.
‫So it takes a C++ file and it translates that into binary individually, each individual C++ file.
‫And then the third step is the linker, which brings all of that together and outputs an executable
‫that we can actually run a single executable.
‫So let's have a look at these standard compilation steps in a little bit more detail with an example
‫file.
‫So imagine that we had a game.
‫CP And it's a very, very simple game because all it does is add one and one together, but to add one
‫and one together is having to use a function that's declared in a different file in the math.
‫H So the math declares.
‫AD, but it doesn't actually define what it does.
‫So that is done over in the math.
‫CP And you can see it's a very simple implementation indeed.
‫Now what happens at the preprocessor step?
‫Well, like I said, it deals with any preprocessor directives, which are things that begin with a
‫hash.
‫So the hash include math, which basically means just copy everything in math into here.
‫So what it does is it takes these two files and it combines them together to create a new output file
‫called Game I basically games include and you can see that it is included the definition from Master
‫H and it's replaced the hash preprocessor directive.
‫So now Game II has got a definition for the ADD operation and then we run the preprocessor on math DHCP.
‫But because it doesn't have any preprocessor directives, basically nothing is changed there.
‫The next step is the compilation is probably the most important and complicated step, because what
‫it does is it takes that C++ in each individual file and converts it in to binary, but it's not complete
‫binary because for example, my game doesn't actually know how to implement AD, it just knows the shape
‫of that add function.
‫So that needs to be filled in later and that's filled in by the linker.
‫So the linker is going to take the binary created for the game obj file and the binary created for the
‫master file and bring them together to make a game.
‫XY which combines the binary for both and finally is a complete executable that we can actually run
‫because it's got the definition for everything it needs.
‫Now, why do we have such a complicated process?
‫The idea here is that it speeds up our compilation time because if I only made a change.
‫To game DHCP.
‫I don't actually need to run the entire compilation process.
‫All I have to do is run the bits involving game DHCP, so I'd run the preprocessor only on the CP,
‫then I'd run the compiler only on the game to I and then I can reuse the math obj file from before.
‫I don't need to recompile it because nothing has changed in that.
‫Similarly, if I only change math dot CP, I wouldn't have to recompile the game obj file, which is
‫why this is a more efficient process and why we're doing it in the first place.
‫So I'd like us to do a little experiment and try and figure out why do we include move a H in and move
‫a CP file?
‫What's the reason for it?
‫Why can't we just compile the C++ file without including moved?
‫H So the experiment we're going to do is we're going to comment out the hash include line.
‫So using a double forward slash to make a comment in front of that line, which will basically make
‫it get stripped out by the preprocessor instead of the preprocessor replacing it with the contents of
‫the file.
‫We're then going to recompile and I'd like you to have a look at the error messages that come out and
‫see what it says to see if you can try and understand what it is that we're including this move for.
‫Pause the video and have a go.
‫Okay.
‫Welcome back.
‫So let's put a double forward slash at the beginning of this line, which basically makes it null and
‫void.
‫And then we're going to do a control alt f 11 and we're going to have a look at the output of live coding.
‫So look, we've got some errors straight away very, very early on.
‫And what it's saying is that you mover is not a class or namespace and there's some other stuff down
‫here.
‫It's saying that primary tech component hasn't been declared that super isn't a class or namespace get
‫owner is an unknown identifier.
‫And basically what this is saying is you've talked about you mover here, but you've not defined it
‫anywhere, you've not declared it anywhere.
‫So I don't know.
‫The C++ compiler says, I don't know what this is.
‫So that's why we are hash, including the mover H because mover H declares the class.
‫It says a U mover is a class and it derives from you act a component and it's got these methods, etc.
‫It's declaring what it means to be that class.
‫So without that declaration, the C++ compiler can't continue.
‫And that's why we need to include that header file.
‫Great stuff.
‫So hopefully you now understand a little bit better the process involved in compilation of C++ and particularly
‫compilation of C++ in Unreal.
‫I will see you in the next lecture.