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 softwares.
- A text editor (such as Notepad, Notepad++, Gedit, TextEdit, Sublime etc.)
- A C compiler (Optionally CodeBlocks IDE).
Text editor: is a software program that enable you to write and edit your programs.
A compiler: translate your program into a series of binary number (0s and 1s) which coputer understands. So whenever you compile a program, the compiler creates a new binary file called executable file which computer can execute.
- What is compiler and why we need it?
- C compilation process.
Read more about-
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.
Why use a 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. CodeBlocks comes with a compiler called GCC to compile C and C++ programs.
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.
Installing CodeBlocks 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.
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.
Configuring 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.
2) Associate C/C++ files with CodeBlocks IDE. Make sure all C/C++ files opens in CodeBlocks by default.
3) Set an idle perspective to use CodeBlocks for beginner.
However, if you want to 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.
2) Inside advanced system properties, click Environment Variables. Alternatively, hit n to open Environment Variables settings.
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.
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.
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.
Remaining is just OK...OK process. Click OK on every window you opened to save all configurations.
Verifying 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.
If gcc --version results in any error, then go back to the configuration step and configure it properly.
0 Comments:
Post a Comment
Please don't enter any spam link in the comment box.