C Language Environment Configuration (The Most Direct Method)

C Language Environment Configuration (The Most Direct Method)

Introduction

Recently, a friend of the author asked how to configure the C language environment. Regarding environment configuration, especially under Windows, the author has previously written a tutorial on environment configuration: Scoop Environment Configuration Record (https://blog.cflmy.cn/2024/11/13/Technology/Scoop/Scoop/). Using Scoop makes it easy to configure the C language environment, but the author’s friend indicated that they only wanted to configure a C language environment without the hassle of setting up other tools.

Given this, I will write a tutorial on how to quickly complete the C language environment configuration.

Configuration Using Tools

This is the simplest method; you just need to download VS or DevC++, and all the environments will be configured automatically. Why bother with manual configuration?

Therefore, this will not be discussed further.

Manual Configuration

Of course, the above method requires installing software, which means we may have to complete many unnecessary operations.

Under this premise, we can complete the environment configuration through the following steps:

  1. Download MinGW64
  2. Add Environment Variables
  3. Test

Download MinGW64

The safest version is to download from GitHub: GitHub-MinGW64-Release (https://github.com/niXman/mingw-builds-binaries/releases). After opening, you will see:

C Language Environment Configuration (The Most Direct Method)

Select the version that corresponds to your system.

Of course, the official GitHub website may not be easily accessible, so the author has pre-downloaded a version, specifically the 64-bit version for Windows: MinGW64-14.2.0-Author Shared Version (https://alist.cflmy.cn/). The file is stored in the C folder.

Add Environment Variables

When the author was still a novice, they did not understand why it was necessary to add environment variables. Looking back now, the author can provide a simple explanation.

After extracting the downloaded MinGW64, you will see the following contents:

C Language Environment Configuration (The Most Direct Method)

Click on the <span>bin</span> folder and open it, then you will see:

C Language Environment Configuration (The Most Direct Method)

This folder contains many executable files. Next, open a terminal in this folder and enter the following command:

ounter(line./gcc.exe --version

You will see the following output:

C Language Environment Configuration (The Most Direct Method)

So these executable files can already perform many operations, but that is not enough. Because in the current folder, the computer knows which executable file you want to run, but in other locations, this operation will not work. Therefore, we need to add environment variables, which means telling the computer where the executable file is when we want to execute it to compile and run C programs. Otherwise, we would have to specify the location of this executable file every time.

Next, open settings and directly type <span>environment</span> in the search bar, and you will see:

C Language Environment Configuration (The Most Direct Method)

Click on Edit System Environment Variables, and you will see:

C Language Environment Configuration (The Most Direct Method)

Next, select <span>Environment Variables</span>, and you will see:

C Language Environment Configuration (The Most Direct Method)

Select <span>Path</span> and click Edit. In the window that appears, click <span>New</span>:

C Language Environment Configuration (The Most Direct Method)

Copy the path of the <span>bin</span> folder from your extracted MinGW64 folder here.

After completing the above operations, click <span>OK</span> all the way.

Testing

The testing method is very simple. Open a terminal and enter:

ounter(linegcc --version

As long as you see the version information displayed, the configuration is successful.

Of course, if you are not sure, you can create a file named hello_world.c in the current directory and enter the following content:

ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line#include<stdio.h>
int main(){
	printf("Hello World!\n");
	return 0;
}

After saving, enter in the terminal:

ounter(linegcc hello_world.c -o hello_world

The <span>-o</span> option specifies the name of the generated file.

Next, just enter in the terminal:

ounter(linehello_world

If it outputs <span>Hello World!</span>, then our configuration is correct.

Conclusion

To be honest, the author personally advocates tools like Scoop for quick configuration, but not everyone likes or needs it. Under this premise, this configuration guide may be helpful.

Notes

This article has been published on the author’s personal blog. Visit the following link for a different reading experience:

Blog Reading

https://blog.cflmy.cn

Accelerated reading site without comments in the country:

https://hexo.cflmy.cn

Leave a Comment