Install and configure CodeBlocks with C compiler

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.

  1. A text editor (such as Notepad, Notepad++, Gedit, TextEdit, Sublime etc.)
  2. 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

Compiler is a program that checks source code file for syntactical errors and translates the source file to low-level machine code, if it is error free.

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

CodeBlocks is available in two variant – with and without compiler. For Windows it comes with MinGW C compiler suite. MinGW C compiler is a windows variant of GCC C compiler.

Download the latest build of CodeBlocks with C compiler from its official website.

Download CodeBlocks with MinGW for windows

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.

  1. Associate CodeBlocks with C compiler. CodeBlocks automatically detects our installed C compiler. Set the detected compiler as default and click OK button.
    CodeBlocks compiler detection
  2. Associate C/C++ files with CodeBlocks IDE. Make sure all C/C++ files opens in CodeBlocks by default.

    Codeblocks file association

  3. Set an idle perspective to use CodeBlocks for beginner.

    Set codeblocks perspective

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).

  1. 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.

    Open run dialog box

  2. Inside advanced system properties, click Environment Variables. Alternatively, hit n to open Environment Variables settings.

    Open System Properties

  3. 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.

    Find path variable

  4. 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.

    Add new Path environment variable

  5. 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.

    Browse for MinGW bin folder

  6. 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.

  1. Open run command window by pressing Win + R. Inside run type cmd and hit enter.
  2. Alternatively, hit Win + S to search, type cmd and hit enter.
  3. 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.

If gcc --version results in any error, then go back to the configuration step and configure it properly.