Setting up C programming Environment

In this topic, we will discuss how C programs can be created and executed in different systems. C programming can be used in a variety of platforms such as desktop computers, embedded systems, etc. We will discuss only how we can set up a C programming environment in desktop computers with different Operating systems.

As we already know C Programming is compiled type of language. A high-level program written in C Programming must be converted to Machine codes to execute. Here we will use another piece of software or tool called a compiler to convert high-level source codes to machine codes and finally linker to link a bunch of object(.o) or machine files, system libraries to produce final executable(.exe) codes. There are lots of ways that we can do this. We can use IDEs(Integrated Development Environment) and just the compilers. Now let’s talk about what IDEs are and how we can use them.

IDE(Integrated Development Environment)

IDEs are a kind of tools/software that can be used to create, debug, run programs written in high-level languages. IDE comes with almost everything (compiler and linker, code editor, etc) bundled to make it easier for the development of the programs. If you are a beginner then, I suggest you start with IDE to start learning. It’s because it hides everything that runs in the background and is easy to set up the environment too. There are plenty of IDEs available in the market. Some of them are open-sourced and some are not. You can use Code Blocks, Dev C++, Turbo C, Turbo C++, Visual Studio, etc. I will demonstrate here one of them(Code Blocks).

Another approach is to install a compiler and linker and use them to produce executable files. In this approach, we have to use code editors like notepad, notepad++, sublime-text to write source code. Then we can compile and run files from the command-line interfaces like cmd in windows, terminal in Linux, etc.

Setting up C Programming environment(Code Blocks) in Windows 11

Code::Blocks is a free, open-source cross-platform IDE that supports multiple compilers including GCC, Clang, and Visual C++. We are concerned only with GCC here because it’s a compiler for C Programming Language. As I have already mentioned it comes with everything bundled. We just have to download the MinGW Code::Blocks because it comes with GCC and debugger. After you navigate to the binary release of code blocks website you will see as shown in the image.

Codeblocks options to download

You can download it either from FossHUB or Sourceforge.nt. After downloading it click to install. Just click as instructed and install in default mode. Now run code::blocks. It looks like.

code::blocks

You can set up and compile the C program from cmd in windows. First, you need to install gcc compiler.

Setting up and compiling C programs from terminal in Linux(Ubuntu)

The default Ubuntu repositories contain a meta-package named build-essential that contains GCC compiler and a lot of utilities. Your system must have already installed GCC compiler. You can check the installed version by typing in the terminal.

gcc --version

If it does not recognize it then you can install it.

First, update the packages list.

sudo apt update

Install the build-essential package by running the command on the terminal.

sudo apt install build-essential

Now you can check the version by typing the gcc –version command on the terminal. And it looks like.

gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 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.

That’s it. Now you can write a C program compile it from the terminal and run it.

Now let’s try to compile a sample C program from the terminal.

First, let’s create a sample.c program using any of the text editors. I am using a sublime text editor. You can also use vi or nano in the terminal.

#include <stdio.h>

int main(){
	printf("C Programming from terminal\n");
	return 0;
}

now you can compile it by running the command on the terminal.

gcc sample.c -o sample

Now an object file called sample will be created on the current directory. You can name it anything you want. Now run the file by

./sample

And the output will be.

C Programming from terminal