Skip to main content

How to Set Up Code::Blocks to Compile and Build C/C++ Programs in Windows

Code::Blocks is a useful IDE that can include compilers for C and C++. In order to use Code::Blocks for C/C++, there are two things to install and one to configure:
1. Download and install the gcc compiler by installing MinGW as described in this article 
2. Download and install Code::Blocks from this site. A link to nightly builds is provided in case you want to try a very recent build but read the documentation first. Some versions come with the MinGW compiler and some do not. In this article, we assume you downloaded the version without MinGW.
3. Configure the compiler and build tools in Code::Block

How to Configure Code::Blocks

When you install Code::Blocks, it tries to detect the compiler. There is a long list of compilers it can use but our interest is MinGW and Cygwin because they are the most reliable, updated open source C/C++ compilers for Windows. For Linux, gcc is a core part of the OS and is installed by default.

To configure Code::Blocks for MinGW proceed as follows:
1. Launch Code::Blocks and open the Settings->Compiler dialog:



2. Select Compiler menu:

3. Select MinGW64 in the "Select Compiler" input box:




4. Select Toolchain tab and use the input boxes labelled 1, 2, and 3 to select the MinGW bin folder path (c:\MinGW-w64\mingw64\bin  in this case) and the various compiler and build tools from this /bin folder as shown below. Be careful to select the correct tools:


5. Create a C or C++ program (see example) and save with file extension .c or .cpp respectively:

5. Select Build->Build and run menu to compile and build the program:


This particular program gives the following (successful) output:


At this point, you have successfully installed and configured the compiler and IDE. If build fails, some troubleshooting is required.

Comments

Popular posts from this blog

How to Install Packet Tracer 6.0.1 for Linux

This article is intended to help me remember the installation process for Cisco Packet Tracer 6 details of which seems to be hard to come by on the web. 1. Log in in to your Cisco Netspace account. Yes, you need to be logged in. 2. The " Download PT 6.0.1 " link on is on the NetSpace home page. 3. Click this " Cisco Packet Tracer " link shown below the folder icon as shown in the figure below: 4. Select  Cisco Packet Tracer 6.0.1 5. Select download location. 6. After completion of download, use your file manager to open that folder and rename the file to something such as "CPT6". It is a shell script so no file extension is required. 7. Change the file permissions to executable using command: sudo chmod 777 CPT6 from a terminal window opened in the download directory. This assumes your downloaded file is renamed CPT6 8. Launch the file with command: ./CPT6 from the terminal window. You will get the message: Self extracting archive... We

How to Install Visual Basic 2017 Offline

This page offers a way to avoid the long and error-prone online installation of Visual Studio which is a massive package. Our interest is limited to Visual Basic and ASP.Net. One can, later, add other tools such as C# and C++. In this page, "VS" refers to Visual Studio. Installing Visual Basic 2017 Offline is not a simple process because Visual Basic 2017 is a part of Visual Studio 2017 that comes as one huge package (up to 35GB) in three versions: Community Edition (Free) Professional Edition (intended for a few people) Enterprise (intended for larger software teams)  Visual Studio by default uses a web-based install process that starts by downloading one of three the bootstrapper package from the VS download page . When you run the bootstraper, it will initiate download of the Visual Studio components that may be up to 35GB in size and takes a very long time to complete. The purpose of this page is to explain how to avoid the headache of this long and tedious

Android Applications with Intellij IDEA - 1

This article applies to Android applications in Windows using IntelliJ IDEA development tools. Windows 7 was used in this example but the explanation will work for other recent versions of Windows. It is quite a task learning how to use mobile application development tools. This page describes how to digitally sign your .apk file which is the  Android application package file. In short, your Android program file. Once you have created an APK file to launch it, simply copy to your device and use the Android file manager to install it. The picture below shows the digital signature keystore file, the unsigned APK file and the signed APK file. The procedure of signing the APK file is quite straighforward but first you must ensure your Java JDK is properly installed and that the Java tools are accessible on your commandline (Windows command console - what used to be called the DOS window). Most important is that your PATH environmental variable (In Windows 7 find this at: Control