Install Code Blocks, GCC compiler & run your first C program – Windows 10

If you are running Windows, it can be a bit confusing to get Code Blocks to run. Especially if you get mixed up in the GCC compiler installation stuff. Also, if you downloaded only the .exe of the IDE CodeBlock’s official site without the fancy extra files. A few years ago when I was trying to execute my first C program, I ran into a bunch of compiler errors and didn’t understand what was going wrong. Mind you, this was the first time I was typing code on my computer. I just didn’t know that we were supposed to set up the GCC compiler separately. So I had to configure the compiler manually and it was a bit time-consuming.

In this post, I will try to present a solution for that problem. Just follow the steps below. This the most efficient and the easiest method to get Code Blocks up and running in a jiffy.

What’s the fastest and easiest way to install and set up Code Blocks with the GCC compiler?

Simple. Download this file and follow the steps below. It is preconfigured with the GCC compiler binary files so we will be up and running in a couple of minutes. We will explain the manual process of custom installing the IDE and the compiler later. Not for the sake of efficiency, of course. Just because knowing the intricacies involved in downloading the GCC compiler is a handy tool and will help you understand the basics of setting up IDEs. Select the full installation option from the second installation window.

Once that’s done, a window like the one above should pop-up on your screen. This is the auto-compiler detection window that will locate all the compilers in the installation folder and ask you to select the default one. Select GNU GCC and click Ok.

Technically, this should complete your installation process. However, if for some reason, you don’t see any automatic compiler detection window, here’s what you can do. 

Start code blocks normally. Head on to the Settings drop-down menu and select Compiler. Then inside the settings window, navigate to the tab titled ‘Toolchain executables’. Under the field ‘Compiler’s installation directory’, ensure that the last folder in the selected path is MinGW. Cross reference with the image below and check if your program files are similarly labeled. That should fix most of the issues with the compiler installation.

The bin folder is where the compiler files are stored. So even if the problem persists even after you select the MinGW folder, it’s probably because the bin subfolder isn’t present. Try doing a fresh re-install on a different hard drive partition.

How to run your first C program in CodeBlocks?

Step 1: Under the tab titles ‘Start here’, click on ‘Create a new project’. This will create a new project folder to store all the different code files.

Step 2: Select Empty project from the different categories displayed in the menu box. Don’t worry about the other options, we will get to know them later in this course.

Step 3: Enter the name of your project, this will be the folder where your individual files will be stored. Also, make a folder on your drive for the code you will write. In the long run, it pays off to organize your files neatly.

Step 4: Make sure that the selected compiler is the one we just installed. Check the boxes as shown in the screenshot to create the debug files.

Step 5: From the topmost toolbar, select the new file icon and create an empty file. This is where we’ll be writing the code. If you can’t see any toolbars, head on to the ‘View’ drop-down, select toolbars and select Main and Compiler, the toolbars should now appear on your screen. Similarly, if you can’t see the Manager window on the left and the Log window at the bottom, you can select to view them from the ‘View’ drop-down.

Step 6: Save the file with the extension ‘.c’ and your desired filename. Notice how the default folder is the project folder we created in step 2.

Step 7: Check the boxes shown below to include the files in the Debug folders.

Step 8: Write the code for Hello World and click the Build and Run icon located in the toolbar on the top. The icon has a yellow gear and a green play logo.

Step 9: You have successfully written your first C program.

Are you still having issues with the compiler?

Please comment below and I’ll be glad to help you out. And if you are not facing any problems and have successfully executed your HelloWorld code, don’t get too comfortable, the course is just beginning!

Leave a Reply

Your email address will not be published. Required fields are marked *