C++ Source Code to Executable | Compilation, Linking, Pre Processing | Build Process Explained Article

C++ Source Code to Executable | Compilation, Linking, Pre Processing | Build Process Explained Article

 

In this Article we will see all the steps involved from writing a C++ program to generating an










executable file and then executing that generated executable file.

Now before getting started, this video is for beginners and i have a simplified a lot 
of things in this video.
let's get started.

now what is C++?

C++ is a general purpose programming language that we can use and write the computer programs.

now the code written in any programming language is called as the source code and the code 
written using the C++ programming language is called as the C++ source code.
you know that we use a text editor we write the code and then we save that in the Computer 
memory as a computer file. Now the file containing the source code written in any programming language is called as the source file and the file containing this C++ source code is called as the C++ source file.
Now how we can differentiate a file containing the C++ source code from any other file.

for example if we have a text file then that text file will have the .txt extension.

similarly the MP3 file will have .mp3 Extension and a PDF file will have .PDF extension.

By looking at this file extension we can say that that particular file is of which type.

now the source file containing the C++ code will be saved with extension of .cpp 
Now this is the most commonly used file extension for the C++ source file.

apart from this you guys can also find .cc extension .cxx Extension and then .cp Extension 
and .C here capital C extension for the c++ source file.

But the most commonly used file extension is the .cpp 
now along with this file there is another type of file which is used for writing the source code in the C++ programming language and they are called as the header files and this header files will have .h or .hpp extension.

The files with the .h or .hpp extension will also contain the C++ source code but there

is a slight difference between the files with the .CPP Extension and the files with the 
hpp Extension and we will talk about that in a moment but here .h is the extension 
for the header file in C programming language and some people you know use that same extension for the C++ header files also.

But if you really want to tell the difference between the header files from the C++ programming 
language and header files from the C programming language just by looking at the file extension then you should use the .hpp extension because it will differentiate it from the C header files. now what is the difference between the files with the .cpp extension and the .hpp extension. The files with the .hpp extension or the header files will contain the declaration of features and the files with .cpp will actually contain the implementation.

for example let’s say we are writing a program and we have created a feature to add two numbers 
and let's call it as add now the header file will contain you know what is the name of the feature, how many values we have to give to this feature so that it can run properly and all these things.

it will not contain the implementation.

The implementation of this feature add will be written with the files with the .cpp extension.

It has a lot of advantage and the you will learn about that later in this video series 
but right now just remember that the C++ source code is saved with .cpp Extension and .hpp extension.
now let's talk about the C++ code.

Here we are just talking about the things in theoretical way, you now we are just drawing

things but when we start writing the code in this video series I will show you all those 
things practically now when we write programs in any programming language in programs we have to do the normal

task again and again.

for example in most of the programs you will be in a situation to convert the string value

from lowercase to uppercase or you want to print some text to the screen or you want 
to read the input from the user.

There are a lot of things that you do again and again while writing the programs.

All programming languages provide the built-in features to do the things which are frequently 
done in the programs.

For example as I said before you now we print some text to the screen, we read the input 
from the user, you know these are the things which are done again and again and all the programming languages provide the built-in features to do all this things.

C++ also provides the built in and features to do all this things and the C++ provides 
them in the form of C++ standard library.

This library is provided by C++ it has all those built-in features.

so let's say in your program you want to print some text to the screen, all you have to do 
is you have to use the built in feature available in the standard library, use that in your program and provide the text that you want to print to the screen to that particular feature and it will do that job.

In the C++ program you can use the features provided by the standard library and you can 
write the code.

now this is about the features provided by the C++ 
In C++ programming language what you can do it you can create a feature and you can share 
it with the other programmers.



for example let's say you are creating a feature to load and MP3 file from the disk and play 
the MP3 file now you can write the code for that and you can share the that code with the other programmers.

The Other programmers who want to load and MP3 file from disc and play it you know they 
can use your code instead of writing that.

so in C++ you can create your own libraries you can say that with other programmers.

so if someone has already created a feature and if they are sharing that then you can 
use it in your code also.

so you can do that by including the external libraries.

You know will talk more about that in the upcoming videos but just remember that you 
know we can use the features provided by other programmers.

you can include the standard library features and also the features developed by other programmers,

if you want in your program.

Normally we all the time use the features from the standard library and the usage of 
the external library depends on the program that you are writing.
Now here if you want to use the feature from the libraries, maybe standard or the external 
libraries, all you have to do is you have to include the header files which contain the declaration of features.

once you include those files, those features will be available in your program and you 
can write the code.

now the next thing is in C++ programming while writing the code if you want you can divide 
your program into multiple files.

if your program is large then you should do that.

it has a lot of advantages.

Now here let's assume that I am writing a C++ program and I have divided my program 
in two different files.

one file name is one and the extension is CPP 
so you guys can see here one.cpp and the other file is two.cpp
now the next thing is we have written the program but we want to execute our program.

we directly can’t execute the code that we have written in the C++ programming language 
because as a programmer we can look at the code and understand what exactly is going 
on but the computers can only understand the code written in the machine language.

so what we have to do is we have to translate this source code written in C++ programming 
language to machine code, so that the computers can understand it and they can execute the 
program.

so now we have to transform your source code from C++ to machine code.

now what we going to do is we are going to create an executable file from this C++ source 
code and then the executable file can be executed by the computer.

Now the process of creating an executable file from the source code is called as the 
build process and now let's take a look at the build process.

so the first step in the build process in order to create an executable file is preprocessing.

we use a program called as pre processor and this preprocessor is a macro processing program.

This preprocessor takes the C++ source code as the input and it does some processing and 
it generates and intermediate code.


C++ Source Code to Executable | Compilation, Linking, Pre Processing | Build Process Explained Article
C++ Source Code to Executable


Post a Comment

0 Comments