How to Run C or C++ Code From Any Drive in CodeBlocks

CodeBlocks is the most popular IDE for the C and C++ programming languages. Using this IDE, any beginners can run and learn how to code. This is the most popular IDE for starting a programming journey because new people usually start with C or C++. Many of us install this IDE and can also run the code. When we create a folder on a different drive and try to run it, we often face errors. Here in this article, we will know how to configure the system to run c or c++ code from any drive/folder in code blocks.


How to Run C or C++ Code From Any Drive in CodeBlocks

Tutorial overview

It's about choosing the right CodeBlocks for your learning and configuring the system environment variable. First, we have to install CodeBlocks with MinGW and edit the environment variable for that.

Install Proper Code::Blocks

We have to install Code::Blocks with the MinGW. To do that, go to Code::Blocks download, then download the "codeblocks- (Current version number) mingw-setup.exe."

CodeBlocks Version for windows 10

After downloading, you have to install it. It is better to install it in the system default drive. Check everything when you are installing Code::Blocks. After installing, you can run a Hello World program to check if it's working or not.

Environment Variable Setup

You must set the environment variable to access the MinGW from your system drives. Before doing this, you should check if it already exists or not. To do that, open your command prompt and run the command 'gcc --version', and it gives any version-related info that means it's already there. Otherwise, you have to set the GCC accessible from anywhere. Here is the steps you have to follow:

  • First, go to the Program Files (of the drive where you installed the Code::Blocks, in default, you will find it in the C drive)
  • Go to CodeBlocks> MinGW> bin
  • Copy the path
C:\Program Files\CodeBlocks\MinGW\bin

After copying, the path will look like that "C:\Program Files\CodeBlocks\MinGW\bin". To set that path as an environment variable, search 'Edit the system environment variables' in the windows search bar.

Edit the system environment variables in the windows search bar

Then go to the 'Environment Variables', select 'path', and click on the 'edit'

Edit environment variables windows 10

Now you have to set the path you copied from the file explorer previously. Then hit save and ok.

MinGW as environment variable path setup

Then you can open the CMD and run the 'gcc --version' command to check if the GCC is working correctly.

GCC version check using CMD

If it shows the version number, then your work is done. Now create a folder and files from anywhere on your computer, and you will be able to run the code. Because your system now knows from where to pull the MinGW and also files for running that C/C++ code.

Author: Sakib Mahmud

This article is from Sakib Mahmud.
(Computer science student from Bangladesh)


  • Published: 1 Dec 2022
  • Last Update: 1 Dec 2022

⚫ More Article On C and C++: