In the previous tutorial, we introduce C programming language and its general overview.
We will continue our C programming tutorial to learn how to setup our environment and C compiler since we need to compile and run our C code when we finish writing it.
Executing our C code will check if everything works as expected.
Although, I will be using windows operating system for these tutorial, it does not really matters if you are on Linux or Mac OS.
Why do we need to compiler C code?
As you can see, when we write our C code, the code is in a human reading format which the computer does not understand.
To make sure computer understands our C code, we need to translate it into machine language code so that it can get executed.
Before we go further to learn about the processes involved in translating our C code to machine code, I will like to mention that if you do not want to install any C compiler in your device, there are many freely available online C compilers you can use to compile and test your C code.
There are 3 steps involved in converting your C code to machine readable code. The steps are listed below.
One of the topics we will cover in C programming language is Preprocessor.
Preprocessor in C is a macro which provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control.
In many C implementations, it is a separate program invoked by the compiler as the first part of translation.
During code compilation in C, the human readable code is translated to binary object code.
Note that at this point the code is not yet in an executable format.
We will not go deeper but remember also that during this stage compilation errors in the code are detected.
Linking is the final stage of C code compilation and execution.
Linking produces a single executable file from different object files.
It links all the object files by replacing the references to undefined symbols with the correct addresses.
Each of these symbols can be defined in other object files or in libraries.
If they are defined in libraries other than the standard library, you need to tell the linker about them.
There are many different kinds of C compilers out there. From the freely available C compilers to paid C compilers.
To give you an idea, I have reference a list of C compilers in Wikipedia.
Depending on the platform that your will use for learning C, we are not going to discuss how to install and setup a C compile.
If you are interested, there are lots of tutorial online that can help you learn it.
I have added a link that will certainly be of help to you.
Downloading and Installing Code::Blocks
We are going to use a C supported IDE called Code::Blocks. Code::Blocks is a multi-platform integrated development environment.
Using integrate development environment when you start learning how to code early will save you the stress of understanding how the same thing can be achieved through command line interface.
Code::blocks comes in different versions. We are going to use the version with gcc compiler already packaged together.
- Go to Code::Blocks official website download page here.
- Click on download binary release.
- Select your Operating System
NOTE: The codeblocks-17.12mingw-setup.exe file includes additionally the GCC/G++ compiler and GDB debugger from TDM-GCC (version 5.1.0, 32 bit, SJLJ).
If you download this option codeblocks-17.12-setup.exe, you will need to download GCC compiler and GDB debugger separately and link them altogether.
The Code::Blocks source code is hosted on Sourceforge.
Click on the Sourceforge link to navigate to the site and download Code::Blocks.
Once the code::blocks download is completed, it is time to start with the installation.
- Go to where the .exe is downloaded.
- Double click on the .exe file to initiate the installation process.
- You will see the image below
Click on the Next Button. Follow the installation instructions until the end.
You can launch your newly installed CodeBlocks IDE to get a first glance on how it looks.
The next dialog that will appear is shown below. Within this time, codeblocks will check if it has detected any compiler.
If you have not installed or properly configured your compiler, it will show error notification – Compiler not detected.
When you see the image below without any error then you know that you have successfully installed codeblocks in your system.
Possible issues during Code::Blocks Installation
1. Compiler not detected
This can be as a result of no c compiler installation or wrongly configured compiler path.
2. Cannot Build or Run Program
This issue usually happens when there is a program running that have not yet been terminated and this causes the run button to appear disabled.
3. Undefined reference to WinMain@16
If you experience this error this error, it is a bit hard to understand what the issue might be.
But in most case, it occurs when you omit or wrongly miss spell the main function on a C file.
We are able to install and open code::blocks and have also looked at possible issues and error we might encounter while programming C with codeblocks.
If you want to read more on this topic and C language programming, you can search online or buy any good C language book.
There is no better time to learn how to write C code than now.
In the next tutorial, we will cover writing your first C program. I know you have been eagerly waiting for this time to come. Click on next button to start.