Programming in C is fun and interesting. In this entire series of C programming tutorial. You will create, edit, compile and execute many C programs. Before we begin to learn about C programs, you must configure your computer with C compiler.
To create and execute a C program you require minimum two software's.
- A text editor (such as Notepad, Notepad++, Gedit, TextEdit, Sublime etc.)
- A C compiler (Optionally CodeBlocks IDE).
In this post, I will discuss about C compiler and steps to setup C compiler along with CodeBlocks in your machine.
The GCC C compiler
Read more about – Compiler and why we need it?
There are many C compilers available such as GCC C, Borland Turbo C, Visual C, Quick C etc. In this entire series of C tutorial, I will work with GCC C compiler.
GCC C compiler is reliable, efficient and popular C/C++ compiler among developers. It is open source and available to download for all most all operating systems. It is pre-installed C compiler in all UNIX based operating systems.
What is CodeBlocks IDE?
CodeBlocks is an IDE (Integrated Development Environment) used to create, edit, compile, debug and execute C/C++ programs in single place. It is very powerful IDE for developing C projects.
In this entire series of C tutorial, I will use CodeBlocks IDE to create, compile, debug and execute C programs. However, there are many other IDE's for developing C projects such as Netbeans, Eclipse, DevC++, Microsoft Visual Studio Code etc.
Download and install CodeBlocks with C compiler in Windows
Download the latest build of CodeBlocks with C compiler from its official website.
Note: You must download the CodeBlocks with MinGW setup executable file.
The download size is about 80MB, which hardly takes 1-2 minutes on good internet connection.
After downloading, run the installer. Installation is simple next...next stuff. The installation wizard will guide you throughout the installation processes.
Configure CodeBlocks and GCC C compiler
On first run CodeBlocks requires few things to gear up. So let us first configure CodeBlocks.
- Associate CodeBlocks with C compiler. CodeBlocks automatically detects our installed C compiler. Set the detected compiler as default and click OK button.
- Associate C/C++ files with CodeBlocks IDE. Make sure all C/C++ files opens in CodeBlocks by default.
- Set an idle perspective to use CodeBlocks for beginner.
However, if you want to go geeky, compile programs from command line with various
gcc options, then set environment variables for C compiler in Windows (in Linux no need).
- Hit Win + R to open run command window. Type systempropertiesadvanced or c:\windows\system32\systempropertiesadvanced. Click OK or hit enter to open advanced system settings dialog.
- Inside advanced system properties, click Environment Variables. Alternatively, hit n to open Environment Variables settings.
- In the Environment Variables window, move down to System variables. Inside the system variables list, find path variable. Select the Path variable and click on Edit, alternatively hit Alt + I to open Environment Variable editor window.
- Inside the environment variables editor window. We need to add a new entry to the Path environment variable. To add a new environment variable entry, click New then click Browse. This will open a file browser.
- Go to your CodeBlocks installation folder, inside that browse for MinGW\bin folder. In my case CodeBlocks bin folder is located under C:\Program Files (x86)\CodeBlocks\MinGW\bin. Select bin folder and click OK.
- Remaining is just OK...OK process. Click OK on every window you opened to save all configurations.
Verify GCC C compiler installation and configuration
To verify the above steps. Open command prompt on windows via any of these methods.
- Open run command window by pressing Win + R. Inside run type cmd and hit enter.
- Alternatively, hit Win + S to search, type cmd and hit enter.
- The easiest one, press Win + X (on win 8 and later versions), then hit C to open command prompt.
In command prompt window type
gcc --version and hit enter. This will show the version information of GCC compiler. On my machine, it shows following output.
gcc (tdm-1) 4.9.2 Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
gcc --version results in any error, then go back to the configuration step and configure it properly.