Release date October 31, 2016 category Tutorial label programming, software
Objective
"⑨ also know series: Mingw-w64 installation Tutorial" This article was written by Rsreland (http://rsreland.net) on September 24, 2016, is "⑨ also know series: MinGW installation Tutorial Ver.2" of the sister article. Mingw-w64 corresponds to the GCC is 6.2.0 version (also for version 6.3.0), the operating environment is the Windows 10 operating system. (Please note that this article is written in time, and software version, to determine whether this article is still valid.) )
This article mainly describes how to install the C language compiler--mingw-w64, the feature is attached to the full details of the actual installation process, the text instead of explaining the role of the hint.
The reason for writing this article starts with one of my ideas: images can convey more information than words, and make it easier for others to understand the author's intentions and thoughts. Therefore, I will install the MINGW-W64 process and procedures, written into this picture-based tutorial, in order to let anyone see this article, can easily follow the image as shown in the correct installation of MINGW-W64.
I want to write a MINGW-W64 installation tutorial that even ⑨ can read.
First, what is MINGW-W64?
The full name of MinGW is: Minimalist GNU on Windows. It actually ported the classic open-source C language compiler GCC to the Windows platform and included Win32API, so you can compile the source code into an executable program that can run in Windows. And you can also use some of the development tools that Windows does not have, under the Linux platform. One sentence to summarize: MinGW is the Windows version of GCC.
The above is the introduction of MinGW, the difference between mingw-w64 and MinGW is that MinGW can only compile to generate 32-bit executables, and MINGW-W64 can compile 64-bit or 32-bit executable programs.
Because of this, MinGW has now been replaced by MINGW-W64, and MinGW has already stopped updating, the built-in GCC stalled in 4.8.1, while the MINGW-W64 built-in GCC was updated to 6.2.0 version.
(Also, if you are interested in MinGW, here are the installation tutorials I wrote: http://rsreland.net/archives/344. )
Second, why use MINGW-W64?
1. MINGW-W64 is open source software and can be used free of charge.
2. Mingw-w64 is continuously maintained by an active open source community and is therefore not obsolete.
3. MINGW-W64 supports the latest C language standards.
4. MINGW-W64 uses the C language runtime of Windows, so the compiled program does not require a third-party DLL and can be run directly under Windows.
5. Those well-known open source Ides actually just encapsulate mingw-w64, making it a friendly graphical interface that simplifies operations, but the internal core is still mingw-w64.
Mingw-w64 is a stable and reliable, continuously updated C + + compiler, use it can eliminate a lot of trouble, do not worry about keeping up with the times, do not worry about the compiler itself has bugs, can rest assured to write programs.
Third, what is mingw-w64 suitable to do?
For a master familiar with MINGW-W64, it can compile any C language program. But for the average person, the mingw-w64 is too primitive, even the graphical user interface does not. This makes people who are accustomed to using the mouse feel very miserable. Although there are some configurations that allow MINGW-W64 to have a graphical user interface, the process is cumbersome.
In addition, when compiling a complex program, you will also need to write Makefile, otherwise only a file of a file compilation, it can be imagined how hard.
But for beginners of C language, MINGW-W64 is the right compiler, at least the black command prompt interface is a programming atmosphere, it feels cool.
At the beginning of the C language, all the code is usually written in a file, and as long as you enter a few simple commands, you can compile the executable file with Mingw-w64. Although VS2015 and other compilers, as long as a mouse click to complete the compilation, but it will automatically generate a lot of engineering files, so that beginners can not touch the mind. MINGW-W64 will only generate an executable file.
If you describe a compiler such as MINGW-W64 and VS2015, the MINGW-W64 is manual, and the compiler, such as VS2015, is automatic. Therefore, the compilation process of MINGW-W64 is more intuitive and easy to understand, and more suitable for C language learning.
All in all, for the average person, MINGW-W64 is suitable for learning C language use, the real work or use VS2015 better. Of course, if you are working under Linux, then code::blocks may be a choice, but the biggest possibility is that you must be accustomed to using GCC to compile the program.
Iv. Downloading and installing MINGW-W64
Before you begin the installation, make sure that you meet the following conditions.
1. Your computer is connected to the network.
2. Your computer's hard drive has 500MB of space left.
3. You have plenty of time now. (The installation process can take up to 10 minutes or more than 1 hours, affected by your current network speed.) )
If you confirm that you have met the above criteria, then you can start installing MINGW-W64.
Note: the pictures in the tutorial are the original proportions of the actual installation, and if you can't see the prompts in the picture, you can enlarge the image without affecting the sharpness. To view a larger image, simply click on the image and you will be redirected to the original size of the image page. If the previous method fails, you can still zoom in on the page by using the browser to enlarge the image, for example, under Chrome, you can zoom in on the page by holding down the Ctrl key and then scrolling the mouse wheel.
1.MINGW-W64 Official homepage (http://mingw-w64.org/)
Description: MINGW-W64 Official website address is: http://mingw-w64.org, home style as shown.
Action: Click on the "Downloads" hyperlink in the red box and go to the MINGW-W64 download details page.
2.MINGW-W64 Download Details page
Description: This is the download details page for mingw-w64. First you see a list titled Pre-built Toolchains and Packages, which is an integration package that contains MINGW-W64 and specific tools. We only install mingw-w64 in this tutorial, so just download mingw-w64.
Action: Click on the "SourceForge" hyperlink in the red box and it will go to the MINGW-W64 download page in SourceForge.
MINGW-W64 download page in 3.SourceForge
Description: Mingw-w64 code and executable files are hosted on the SourceForge and can be downloaded directly on this page mingw-w64. Mingw-w64 is very complex, and most of the compilers are, in order to adapt to various operating systems, their components will exist in a variety of different versions to suit different environments. So, we download the MINGW-W64 installer directly, it will automatically download the appropriate components as needed, and organize them together.
Action: Clicking on the "Download mingw-w64-install.exe" hyperlink in the Red box will download this mingw-w64 automatically installed program.
4. Wait for the MINGW-W64 installer to start downloading
Description: After 5 seconds, the browser will download Mingw-w64-install.exe automatically.
Action: Just wait.
Note: If the browser does not download automatically, you can click the "Direct link" hyperlink in the Yellow box to download it manually. If the download speed is very slow, you can click on the "Mirror" hyperlink in the Green box and select a mirror site close to you, you may get a higher (not guaranteed) download speed.
5. Downloading Mingw-w64-intall.exe
Note: If your browser is chrome, a download tag will appear in the lower part of the browser.
Action: Just wait.
6.MINGW-W64 installation program
Description: This is the installer for mingw-w64. It is essentially a download program that, depending on some of our settings later, selectively downloads the appropriate components and organizes them together. So, before running, make sure the network is unobstructed and you have plenty of time, because depending on your speed, it may take some time to download.
Action: Run Mingw-w64-install.exe with the mouse double-click.
Note: If it does not work, or the installation error, you can right click on it, and in the Pop-up window select the "Run as Administrator" option, rerun Mingw-w64-install.exe, basically can solve most problems.
7.MINGW-W64 Installer Welcome Interface
Description: Welcome to the MINGW-W64 Online installation program.
Action: Click on the "Next" button in the red box to proceed to the next installation step.
8. Get mingw-w64 file information from the server
Description: Here the program is linking the server to get the file details of the mingw-w64 stored in the warehouse.
Action: Just wait.
9.MINGW-W64 Version Selection
Description: In this interface, you can download the required components by selecting different options depending on the development environment you want to build.
Action: Select the appropriate option in the Version, Architecture, Threads, Exception, Build revision drop-down list, which will be described in more detail next.
10. Select the GCC version
Description: Version refers to the GCC versions, and if there is no special requirement, the highest version number is generally chosen.
Action: In this version, the highest version is 6.2.0, select it.
11. Select the computer system architecture
Description: Architecture refers to whether the computer system is 32-bit or 64-bit, according to your computer system to make the corresponding choice.
Operation: My Computer system is 64-bit, so I chose x86_64, if you are 32-bit system, then select i686 can.
12. Select the operating system interface protocol
Description: There are only two operating systems in the world that are compliant with the POSIX protocol, and Windows. As this joke says, if you want to develop Windows programs, you need to choose Win32, and you need to choose POSIX for developing programs under other operating systems, such as Linux, Unix, Mac OS, and so on.
Action: I only developed a program that runs under Windows, so I chose Win32.
13. Select the exception handling model (64-bit)
Description: Exception handling is important in the development process, where you spend most of your time working on various anomalies. If you have previously chosen 64-bit, there are two exception-handling models for you to choose from, and Seh is a new invention, while Sjlj is ancient. SEH performance is better, but does not support 32-bit. SJLJ good stability, support 32 bit.
Action: I chose Seh here.
14. Select the exception handling model (32-bit)
Note: After selecting 32 bits, you can use the dwarf and SJLJ two exception handling models. Similarly, the performance of dwarf is better than that of SJLJ, which can not support 64-bit.
Action: It is recommended to select Dwarf.
15. Establishment of revisions
Description: I haven't figured out what to do for a while. (People who know please leave a message)
Action: Select the default option.
16.MINGW-W64 Version Selection complete
Description: The green box is my mingw-w64 installation configuration list, GCC is 6.2.0, the system architecture is 64 bits, the interface protocol is Win32, the exception handling model is Seh,build revision is 1.
Action: Click on the "Next" button in the red box to proceed to the next step.
17. Select the MINGW-W64 installation directory
Description: Select the directory where MINGW-W64 will be installed. The installer will install MINGW-W64 on the C drive by default, while in the Windows operating system the C drive is the system disk, and the operating system will be installed on this disk, and as a general rule, we try not to install the application software on the system disk. Because the previous computer uses a mechanical hard disk, and the mechanical hard disk frequently read and write will reduce efficiency, so try to put the operating system and application software under different hard disk partitions. Of course, today's computers are mostly equipped with solid state drives (SSDs) and are often used as system disks, so there is no question of read and write efficiency. So if you're still using a mechanical keyboard, put mingw-w64 on other non-system disks, and if you use SSDs, you can put them in the default location of the installer prompts, or anywhere else.
Action: Click the "Browse" button in the red box to change the installation location of the MINGW-W64.
18. Change the installation location of the MINGW-W64
Note: Click "This Computer" in the green box to open a tree list and find the location where you want to install the MINGW-W64. You can also create a new directory by clicking the "New Folder" button in the Yellow box.
Action: After selecting the installed directory, click the "OK" button in the red box, then the installer will install the MINGW-W64 there.
19. Confirm the MINGW-W64 installation directory
Description: The space available in the interface refers to the directory that you choose, the rest of the hard disk partition, and the mingw-w64 occupies at least one MB of space. Create shortcuts in Start menu is a shortcut that creates a mingw-w64 in the start menus and is generally checked by default.
Action: After confirming the installation directory, click the "Next" button in the red box to start the installation of MINGW-W64.
20. Start Download Mingw-w64 Ontology
Description: The installer starts to connect to the server and download the Mingw-w64 ontology file, depending on your network environment, the time required for the download will vary, if you have other things to do, you can click the "Cancel" button to cancel this installation.
Action: Just wait.
21.MINGW-W64 Download Complete
Description: Mingw-w64 has been downloaded, we can find its various component files in the previously selected installation directory.
Action: Click on the "Next" button in the red box to proceed to the next step.
22. Close the MINGW-W64 Setup program
Description: The MINGW-W64 installer has completed its mission, but MINGW-W64 has not been installed yet, and we need to configure it to compile the source code properly.
Action: Clicking the "Finish" button in the red box will close the Mingw-w64 installer.
23.MINGW-W64 installation directory
Description: Mingw-w64 Download complete after the installation directory, contains 1 folders: mingw64,3 files: Mingw-w64.bat, Uninstall.exe, Uninstall.ini, and a shortcut: Mingw-w64. Although the MINGW-W64 has been downloaded, but not installed, we also need to configure the operating system environment variables, add the Mingw-w64 bin directory, so that the operating system can find those compilation tools.
Action: Double-click the "mingw64" folder in the Red box to enter it.
24.mingw-w64 's Mingw64 folder
Description: Mingw64 contains a series of folders, depending on the name of the folder, presumably can guess what they do, but we do not need to fully understand, just need to know the bin folder, the storage of those compilation tools.
Action: Double-click the "Bin" folder in the Red box to enter it.
Bin folder for 25.mingw-w64
Description: The Bin folder contains a number of EXE-named executable programs, these are the tools required for development, such as: Gcc.exe is used to compile C programs, G++.exe is used to compile C + + programs, and Gdb.exe is used to debug the program Debug tool.
Action: Click the Address bar in the Red box and copy (Ctrl + c) that string of addresses.
26. This computer
Note: We have copied the address of the Bin folder of the Mingw-w64, and then simply add it to the environment variable of the system to complete the MINGW-W64 configuration.
Action: Right click on "This computer", in the pop-up menu, click on the "Properties" item in the red box.
27. Computer system window
Note: This window can also be opened by means of "system and Security", "Control Panel" and "System". If you don't know if your system is 32-bit or 64-bit, you can also check it here.
Action: Click on the "Advanced system Settings" link in the red box to open the "System Properties" window.
28. System Properties Window
Description: The so-called "environment variable" is actually the default installation directory of various programs, where there are executable programs.
Action: Click the Environment Variables button in the Red box to open the Environment Variables window.
29. System Environment Variables window
Note: In this window we can edit the environment variables of the system, many software will automatically edit the environment variables when installing. The installation of MINGW-W64 is very simple and can only be edited manually by us.
Action: First click on the "Path" item in the green box and then click on the "Edit" button in the Red box.
30. Edit the PATH environment variable
Description: This is the editing interface in Windows 10, which is clearer and easier to operate than the previous version, and is not prone to error.
Action: Clicking the "New" button in the red box will create a new blank variable position.
31. New environment variables for MINGW-W64
Note: You can now complete MINGW-W64 configuration by simply copying the bin folder address of the previously copied mingw-w64 to the new blank variable location.
Action: Paste the Bin folder address into the input box in the red box.
32. Add MINGW-W64 environment variable is complete
Description: The environment variable for MINGW-W64 has been added.
Action: Click the "OK" button in the red box, the MINGW-W64 configuration is complete.
33. Start the command prompt
Note: In order to test whether the MINGW-W64 is configured successfully, we need to execute a command in the command prompt. So to start the command prompt, it's worth noting that each version of Windows starts differently, but you can open it by opening the run window and typing "cmd".
Action: Right click on the Start button and click on the "command Prompt" item in the red box in the popup menu.
34. Command Prompt
Description: Mingw-w64 is a command-line tool that can only be called from a command prompt if it is not mated to other software.
Action: Enter "Gcc-v" and press ENTER to display a list of MINGW-W64 components.
35.MINGW-W64 Installation Complete
Note: If your "command Prompt" displays a large list of component information, it means that your mingw-w64 is already installed, congratulations!
Operation: From now on you can use MINGW-W64 to compile the C program.
v. Use of MINGW-W64 compiling source code
MINGW-W64 does not have a graphical user interface, it is actually a set of command-line Toolsets, and any action can only be performed by entering a command in the command prompt. For programming, this command-line tool is particularly unique in that all operations can be done without having to leave the keyboard with both hands. Although the mouse is easy to use, but the efficiency is still less than the keyboard. Furthermore, developing a graphical user interface for a program is a very troublesome thing, because it is closely related to the platform and you have to consider the different platforms.
Of course, there are many integrated development environments (IDES) with beautiful graphical user interfaces in the world, some of which are built-in compilers such as Code Lite, Code::Blocks, and so on. Mingw-w64.
A. Compiling commands gcc
Format: Full name of GCC source code file
Example: GCC hello.c
Note: "GCC" is the MINGW-W64 built-in compiler command, "HELLO.C" is the name of the source code file we want to compile.
Note: First, there is a space between the "GCC" command and the file name of the source code. Second, the file name must be complete and correct, and the suffix ". C" cannot be omitted.
Because MINGW-W64 was originally a product of porting GCC to Windows, the operation was just like GCC, where commands were typed into "terminal" and Windows was typed into "command prompt."
B. Creating a hello.c source code file
Before compiling the source code with the "GCC" command, we first need to have a file that stores the C language code. C language source code files are actually ordinary text files, the only difference is that the suffix name is different, the text file suffix is ". txt", and the C language source file suffix is ". C".
So we create a new text file, the name can be arbitrarily taken, I will name it here as "Hello", now the full name of the file is "Hello.txt". Then we only need to change "hello.txt" suffix ". txt" to ". C" suffix name, so that the C language source code file "Hello.c".
C. Write Hello, World source code
Here, use the Windows-brought Notepad or any text editor, open the "hello.c" source code file, and then type the test code shown in the file, and finally save the file. Now that the source code file for the test is ready to be completed, we can compile the next step.
This code is the most basic of the Hello, the World program, will display on the screen "Hello, World" this text. I believe this is the most people to learn programming, the first program, so there is no more to repeat.
D. Compiling hello.c Source code
Previously said MINGW-W64 is a command-line tool that does not have a graphical user interface, so the compile operation needs to be done at the command prompt.
First we open a command prompt, and then we want to locate the working directory to the source code file storage location, this step is very important, do not touch the command line tool of the person, often will error here. The DOS command "CD" Can change the current working directory, by adding the target working directory after the "CD" command, such as the third row, to relocate to the e-drive under the A directory. Once you have finished using the CD command, you will also type the address of the directory you are targeting again, so that you can transfer past, but you only need to type the drive letter, and you do not need to type the full address, such as line fourth. After relocating the working directory, as shown in line fifth, the working directory has changed from C:\Users\lenovo to E:\a.
Now we just need to execute the "gcc hello.c" command, and we can compile the source code into an executable program.
E. Building A.exe executables after compilation
As shown, A.exe is the executable program generated after compilation. Because we did not specify the generated program name at compile time, mingw-w64 by default the program is named a, plus the suffix is a.exe. If we want to specify the generated program name at compile time, we need to use the "-o" option for the "GCC" command.
F. GCC commands with the-o parameter
Format: GCC source code file name---the name of the compiled program
Example: GCC hello.c-o hello.exe
Description: the "gcc" command has a number of built-in options, where "-O" indicates the name of the compiled file after the word that follows it.
Note: the option "O" is a lowercase letter in English, not a numeric zero, and it can only be followed by the file name that you want to set.
This method of naming at compile time seems to be very chicken, at first glance it seems to just save us some time, after all, we can also manually rename after compiling. This idea is because our program is very simple, only one source code file, will only compile a program. When our program becomes complicated, we may compile a complex program in a working directory, then we must use the-o option, otherwise the compiled program is called A.exe, it will be overwritten with each other when it is generated.
G. Compiling hello.c into hello.exe
Also to locate the work directory we are working on, and then execute the "gcc hello.c-o hello.exe" command, it will compile to generate a name hello.exe executable file.
H. Build Hello.exe executables after compilation
After executing the "GCC hello.c-o hello.exe" compilation command, the Hello.exe executable is generated in the working directory, which is the final result we get.
I. Double-click Run Hello.exe
Running the compiled Hello.exe program with a mouse double-click launches a Command Prompt window and displays the characters "Hello, World" in it. This means that we have successfully completed a compilation and compiled the C language code into a program that the computer can execute.
J. Running Hello.exe at the command prompt
If you want to run a compiled program, you do not have to double-click the program to start it, or you can enter the compiled program name directly from the command prompt, for example, enter "Hello.exe" or run the program directly. You can even omit the suffix of the program, just enter "Hello" and the program will run correctly.
Vi. some additional settings
These additional settings can make the mingw-w64 more convenient to use. Because the "gcc" command is a bit of a hassle, every compilation has to enter a string of characters like "GCC hello.c-o hello.exe", so in order to simplify this step, we use the "make" command instead. Just "make" is a tool under Linux and UNIX, so some additional modifications are required in MINGW-W64.
1). Create a copy of the Gcc.exe CC.exe
First copy a copy of "Gcc.exe" and rename it to "CC.exe".
2). Create a copy of the Mingw32-make.exe Make.exe
Copy the copy of a "Mingw32-make" to "Gcc.exe", and then rename it to "Make.exe".
3). Compiling the source code with the make command
Now we can use the "make" command to compile the source code, just enter "make Hello" to compile and build "Hello.exe".
Seven, advanced
The above is just a simple way to compile the source code, for a single or a small number of source code files, if it is a complex large program, to use makefile to organize the source code, you need to Mingw32-make (modified use make) command.
If the program compiles or runs in error and you need to debug the source code, you can use the GDB command to help us determine where the problem occurs.
If the code does not have an obvious compilation error and there is no logic error at run time, then when the program is finally compiled into a published version, we also have to consider the problem of compiling optimizations so that the resulting program files have smaller volumes and higher operational efficiency. The GCC command has 00,-01,-02, -03 of these optimization options, where-00 is the default option, meaning no optimization, the remaining few options with the number of increases, the degree of optimization will gradually increase.
Viii. List of issues
Here is a list of some of the issues that can be foreseen and how to solve them.
①. If the Auto Setup program cannot download components
Description: If the network environment is not good, or due to broadband provider restrictions, it may cause the program to download components very slow, or even fail. At such times, instead of installing the program, we try to manually download MINGW-W64 's compressed package directly. The advantage of this approach is that third-party download software is available, and most of this download software provides accelerated download and breakpoint continuation. Basic can solve the problem that cannot download.
Action: as shown in. You can see this section of the page by pulling down the MINGW-W64 download page in chapter Fourth and section 3rd SourceForge. Among them, the link inside the red box, is mingw-w64 the compression package manual download link (6.3.0 version), simply select the corresponding link to download according to the need. For example: X86_64-win32-seh, x86_64 refers to 64-bit, Win32 refers to the development of Windows programs, SEH refers to the exception handling model.
After the MINGW-W64 compressed package is downloaded locally, it is decompressed and can be configured as usual.
This document permits:
This article is written by Rsreland (Ryland), using Rsreland documentation License License and following its content, your rights and obligations are described in http://rsreland.net/licence.
http://rsreland.net/archives/1760
"⑨ also know series: Mingw-w64 installation Tutorial" The Windows version of the well-known C + + compiler gcc (mingw-w64 can choose the version when installing)