

Let’s say you have a C++ file called helloWorld.cpp … If you are on Windows Using and IDE like CodeBlocks Once this is done, you now have a functioning executable file! How to Compile a file

The compiler made all the blocks but the linker is the one that sticks them all together to finally create a house. Think of it as having all the necessary blocks to build a house. In order for you to have a final executable program, another utility known as the linker must combine your object files with the library functions necessary to run the code. You can include these libraries with preprocessor directives, but the preprocessor doesn’t automatically add them to your code. There is a final important step to reach an executable program.Ĭ++ contains a vast library to aid in performing difficult tasks like I/O and hardware manipulation. While the object file that the compiler just created is likely enough to do something on your computer, it still isn’t a working executable of your C++ program. This will also uncover any syntax errors that are present in your source code and will throw an error to the command line.įinally, if no errors are present, the compiler creates an object file with the machine language binary necessary to run on your machine. Next, the compiler works through the preprocessed code line by line translating each line into the appropriate machine language instruction.

Preprocessor directives cause the preprocessor to change your code in some way (by usually adding some library or another C++ file). The preprocessor searches for any preprocessor directives (lines of code starting with a #). When you run a compiler on your code, first, the preprocessor reads the source code (the C++ file you just wrote). How compilers workĬompilers are utility programs that take your code and transform it into executable machine code files. Languages like JavaScript and Python have components that get translated into C++ or other low level languages before they get compiled, effectively making them “higher” languages than C or C++.īecause computer architecture is made up of electronic switches and cables that can only work with binary 1s and 0s, you need a compiler to translate your code from high level C++ to machine language that the CPU can understand. Languages like C, C++, and COBOL are a little higher and need to be compiled down. So, we humans developed programming languages to make it easier to develop software.Īssembly language is a direct 1 to 1 with machine language. While it would be possible to program in binary, it would be incredibly tedious and time consuming. Machine language is entirely made up of binary bits, or 0s and 1s. When all is said and done, computers only understand one language, machine language. In order to get started with C++, you will need to learn a little about compilers and how C++ runs on your computer.
