Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and use the compiler of C language

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the C language compiler how to install and use the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe everyone read this C language compiler how to install and use the article will have some gains, let's take a look at it.

What is compilation?

We call what people say natural language. Similarly, communication between machines uses machine language. We know that the exchange between machines is based on wires, and the change of current transmits relevant information. Commonly speaking, there are two states in the circuit, one is there is electricity, the other is no electricity. If the number 0 represents no power and the number 1 represents one, then successive state changes can be converted into a string of information consisting of zeros and ones. Communication between machines is based on such strings of information2.

1. Here there is no electricity is a more popular saying, in fact, should be called high level, low balance.

2. Such a string of information, also known as machine language, in the two common structures of processing information in computers, memory is responsible for storing such information, the method is also very simple, each memory unit records the 0 and 1 of the response respectively, this is the memory storage process, these 0 and 1 are read out in a certain order, this is the memory reading process. The CPU reads these information strings at certain intervals (for example, in a 64-bit computer, he can read 64 such information strings at a time). These information strings have different effects. Some of them are instructions. For example, after reading certain strings, it performs addition, etc. These are the knowledge of the principle of computer composition. If you are interested, you can go to the relevant manual for learning.

Part of the content of machine language is fixed instructions. We replace these fixed instructions with some mnemonics (such as ADD, JUMP, etc.). This is assembly language. Assembly language needs to replace these fixed instructions before it can run, a process we call assembly.

Assembly languages are more closely related to machine languages and are harder for humans to understand, so they are called low-level languages, or low-level languages. As we said before, machine language runs on different machines. Different machines have "dialects," that is to say, different machines understand the same information string differently. This also leads to whether it is machine language or assembly language, it can only run on the corresponding machine, and it needs to rewrite assembly code on other machines.

Assembly is not a good tool for programming. In 1972, Dennis Rich developed C, a language better suited for programming than assembly language (which was true at the time, but later generations beat the waves on the beach with more ease and elegance as the times changed), expressing an operation in terms of symbols, which were code (C code, suffixes.c or.cpp, plus.h as a header file). This code is readable to humans but completely unreadable to machines, so how do you make it readable? This introduces the existence of compilers.

C language is close to natural language, but relatively far away from machine language. This kind of language that is easy for people to understand is called high-level language. Compilation is the process of converting a high-level language into a low-level language.

Supplement: In fact, there is another way to translate called interpretation, the difference between compilation and interpretation is: compilation will translate all high-level languages into low-level languages at once, and interpretation will interpret high-level languages into low-level languages one sentence at a time. Famous interpreted languages include JavaScript and Python. Java bytecode is also interpreted on JVM.

What is a compiler?

Compilers are programs that translate high-level languages into low-level languages.

The most popular C compilers are:

GNU Compiler Collection or GCC (the Windows version of GCC compiler is called MinGW)

Microsoft C or MS C (also known as MSVC)

Borland Turbo C or Turbo C

These C language versions not only implement the ANSI C standard, but also make some extensions on this basis to make it more convenient and perfect.

GCC is a compiler used by Unix-like operating systems (Linux, macOS, BSD, etc.), MSVC is a compiler used by Windows, and the results of compilation cannot be mixed, that is, executable files compiled using MSVC cannot run on Linux (in addition, linux executable files are not.exe).

How do I install and use these compilers (for Windows)?

MSVC can only be installed on Windows platform, the installation method is also relatively simple, directly install visual studio family bucket (To give a few common examples, visual C++6.0, visual studio2010, visual studio2017 all have the compiler), will come with MSVC compiler, in general, directly using VS family bucket can achieve very good learning results, but if you want to use the code editor plus compiler development method alone, you can refer to this article: VSCode Configuration C++ Environment Method Steps (MSVC)

MinGW installation is also relatively simple, if you use codeblock, then some versions have their own MinGW, you can use these MinGW directly, in this article VSCode configuration C++ environment method steps (MinGW) two tools also provide MinGW download, want to use code editor + compiler development method can also refer directly to this article. Next, let's talk about how to install MinGW separately.

Download link: sourceforge

Download and install directly according to the requirements.

Note that the installer is downloaded, the installer body is relatively small, you need to network to obtain the MinGW body, the overall installation needs about 400M to 600M, different versions and sizes.

After installation, you can find the MinGW64 folder under the installation path and add the bin folder to the environment variable.

Due to space constraints, the detailed installation of MinGW is described in a separate article. Small partners can go to: How to install MinGW? GCC Compiler Installation Tutorial! Views

edit code

Write a program using Notepad or a code editor (Notepad is not recommended here, vscode is used for small series).

Start by entering the directory where you want to create the file from the command line.

compilation process

Compilation process is divided into four steps: preprocessing, compilation, assembly, linking.

1. pretreatment

Preprocessing mainly deals with "#include","#define" and other preprocessing commands in the source file.

The main tasks of pretreatment are:

(1) Delete #define, expand macro;

(2) Processing conditional compilation instructions, pre-processing program first judges the conditions, and modifies the source code according to the conditions;

(3) Delete comments;

(4) Add line number and file name identification for debugging

(5) Delete "#include" and insert the corresponding header file;

Use g++ -E test.cpp -o test.i command to get test.i file after preprocessing

2. compilation

To generate assembly code, use the command g++ -S test.i -o test.s. to generate the assembly file test.s. Of course, you can get the assembly file directly from the test.cpp file.

3. compilation

Converting assembly code into machine instructions to generate object binary code.

Generate the test.o file using the command g++ -c test.s -o test.o

4. link

Converting object files into executable files by linking library files

Use the command g++ test.o -o test.exe

Of course, under normal circumstances, you can directly use g++ test.cpp -o test to generate executable programs.

run the program

Finally, use the command test.exe to run the program.

You can also click on the exe file to run it.

About "C language compiler how to install and use" the content of this article is introduced here, thank you for reading! I believe everyone has a certain understanding of "how to install and use C language compilers" knowledge. If you still want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report