Code blocks is an open-source & powerful C/C++ compiler that has the support of many GNU tools such as GDB. GDB is a GNU debugger that is used to debug C/C++ programs.

In this article, we will see how to download and install code blocks IDE on our computers.

Download & Install code blocks :

Click on this link to download code blocks.

After downloading the .exe file, Right-click on the executable, select Run as administrator and follow onscreen instructions to install code blocks in your computer.

Creating a new project:

After installation, open Code Blocks IDE and click on File > New > Project.

  • Select the application type as a console application and click on Go.
  • In the next window, select C as your language and click on next.
  • Give a meaningful project name in the next window and click on next. Finally, we have created a C project in Code Blocks.

Code, compile & build:

In the left side panel, click on the project name to expand the project tree and click on “Sources > main.c“. Copy and paste the below source code in the editor and click on “build & run” in the top menu bar.

#include <stdio.h>
int main()
{
    printf("Hello, world!");
    return 0;
}

We have successfully created, compiled, and executed the C program in CodeBlocks IDE.

Configuring the GNU Debugger:

Now click on “Settings” in the top menu bar and select Debugger. In the left side menu-> select “Default” under “GDB/CDB Debugger”. In the right-side panel, click on […] and select the executable path of “gdb.exe”  and click on OK.

gdb.exe Executable path : C:\TDM-GCC-64\gdb64\bin\gdb.exe

Debugging the program:

Now if you see, there will be line numbers visible at the left side of the program. Just click right beside the line number you will see a red dot appeared at that point. That is known as the Breakpoint. Now the execution of the program will stop at this point if you compile and run it.

Reference Video:

Categorized in:

Tagged in: