How C++ Works, IDE’s, Compilers, Linkers

c-compiling-binarymove

In this article we are gonna see some basic terms and the software’s used in the development of c++, the compilers, archivers, linkers, toolsets, IDE’s and also we are gonna see how c++ works or what is the process to get an executable or an exe file from an c++ source file.

So first we are gonna see what is a toolset. The computer can only understand the machine language code which is the combination of 0’s and 1’s. In other words, the computer can only execute the code written in 0’s and 1’s. The three basic tools used to build c++ applications are the compilers, the linkers and the archivers. So we are gonna use these three tools and we are gonna convert our c++ source file to an executable one, which we can execute. A collection of these programs and possibly other tools is called toolset. Or we can say that the combination of the compilers, the linkers, and archivers together called as toolsets. So now we are gonna see the compilers, archivers and the linkers in detail.

The compiler takes c++ source files as input and produces object files, which contain a mixture of machine executable code you know the zeroes and one’s the code in zeroes and one’s, and also some symbols references to functions and data. So in our program, we are gonna use some functions and we are gonna refer the library functions you know which are provided by the c++, and also we are gonna refer some data in some other files. So the object file created by this compiler is gonna contain the code of our program, you know in 0’s and 1’s and also some references to this functions and data. Then the archiver which takes a collection of object files you know which is generated by the compiler, as the input and it produces a static library or a archive which is simply a collection of object files grouped for convenient use.

And next the linker.

The linker takes a collection of object files and libraries and it resolves their symbolic references to produce either an executable or a dynamic library. So once we have this object files, we pass that object file to the linker. The linker is gonna take the group of object files that we have passed, and the linker takes a collection of object files and libraries and it resolves their symbolic references to produce either an executable or a dynamic library. So once we have this object files, we pass that object file to the linker. The linker is gonna take the group of object files that we have passed, and its gonna link them. So now we are gonna see what is an executable and a dynamic library. An excutable or a application is simply any program that can be executed by the operating system. For example we have the notepad, and the wordpad, and any other application which we execute on our computer. you know the operating system can easily execute. A dynamic library is also called a shared library, is like an executable except that it can’t be run on its own. An application file can make use of this dynamic library files. On Windows operating system, these dynamic library files are also called dll files are also called as dll files or dynamic link libraries.

C++ Make machine executable
C++ Make machine executable

Ok, now we know about the compilers, the linkers, the archivers, the toolsets you know how c++ works? or what is the procedure to get an application or a executable from the c++ source file. So first we have the c++ source code, and then we are gonna compile that source code using the compiler, and this process is called compilation and we will get the machine code version. This machine code version is gonna contain some symbolic references to some other functions, data or some references to the library functions provided by the c++. So next what we are gonna do is we are gonna link this object file or the machine code version with c++ library using the linker and the process is called linking. Here that references are resolved and we will get the complete machine executable program.

So this complete machine executable program is an application which can be executed by the operating system. Now we know how c++ works or the procedure to get the application or the executable from a c++ source file, you know what are the available toolsets and command line tools that we can use to do that. So the command line tools for various toolsets are, if you are gonna select

So the command line tools for various toolsets are:

C++ command line tools
C++ command line tools

If you are gonna select gcc toolset then, you will get the g++ compiler, g++ linker and also ar or ranlib archiver.

Similarly, for visual c++ toolset we have their specific compiler, linker and archiver and similarly for you know Intel, for Windows Linux, Metrowerks Comeau and all this different toolsets contains different compilers, linkers and archivers. Now what is an IDE and why to use an IDE?

 

Now what is an IDE and why to use an IDE?

  • The compiler, linker and archiver are command-line tools.
  • To pass the input files. To pass the input files, you know name of the input file and output file together with some necessary configuration information to the compilers, linkers and archivers as text in the command prompt and we will get the specific output from that specific programs.
  • Invoking these tools by hand is tedious again and again. For example, when you develop a program, you want to check that program, again and again, to make sure that program is working properly while developing. So at that time invoking these tools by command prompt you know it’s tedious you know cant write all these things again and again. It is time-consuming. So to solve that we are gonna use the IDE’s.
  • An ide provides a graphical interface for organizing a collection of source files and describing the binary files that should be nerated from them. So we just need to click some buttons in the ide you know in the graphical user interface, and then the specific compilers, linkers, archivers and all those things are called automatically and we will get the application.

Some available IDE’s for c++ are:

The visual c++, the code warrior, c++ builder, dev c++, code blocks and many others are available. I recommend to use code blocks ide because its available for all the platforms (windows mac linux), and also its very simple to set up.