Use GCC in Windows

Source: Internet
Author: User

 

Use the GCC compiler in Windows:

Use mingw

 

1. First introduce mingw

 

 

 

Mingw refers to the compilation environment for generating pure Win32 executable files using only free software. It is a nickname of minimalist GNU on Windows.

 

In fact, mingw is not a pure C/C ++ compiler, but a set of GNU tools. In addition to GCC, mingw also contains some other gnuProgramDevelopment tools (such as gawk bison ).
Mingw is developed to provide a GNU working environment for those who do not like to work in the Linux (FreeBSD) operating system and stay in windows.
Therefore, with mingw, we can use the GNU program development tool as in Linux.
GCC is the core of mingw. GCC is a compilation system that supports many computer programming languages, and is the closest to the standard in terms of implementation of language standards. In addition, GCC can be transplanted to almost all currently available computer platforms. (Devkitpro is also installed on my computer, which contains the GCC arm (for GBA/DS/gp32) and MIPS (for PSP) versions .)
GCC itself does not have the IDE interface as VC does (in Windows There are also Dev C ++ and other ides that support mingw compiler ).Source codeYou can select any text editor you like (it is said that Microsoft developers, including VC, do not use the IDE editor provided by VC, but choose the GNU Vim editor ). Then, use make and other tools to compile, Link, package, and publish software projects. Like the CVS (SVN) SourceCodeVersion control tools allow anyone in any corner of the world to participate in software projects.

 


 

2. Download mingw

 

One way isSourceForge (http://sourceforge.net/project/showfiles.php? Group_id1_24351_download A mingw-2.0.0-3.exe file.

 

However, codeblocks is installed on my computer and mingw is provided.

 


 

3. environment variable configuration

 

In (System Properties> advanced> environment variables> system variables) (The following directories are changed based on the location of your computer's mingw)

 

A. Add "C: \ Program Files \ mingwstudio \ mingw \ bin" to the path value ". This is the path to find the GCC compiler. If there are other content in the path, use a semicolon to separate it.

 

B. Create the LIBRARY_PATH variable and add "C: \ Program Files \ mingwstudio \ mingw \ Lib" to its value ". This is the path for standard stock placement.

 

C. Create the c_include_path variable and add "C: \ Program Files \ mingwstudio \ mingw \ include" to its value ". This is the path of the include header file.

 


 

4. Verify that GCC is running properly

 

In the CMD Console window, enter gcc-v. If the installation is successful, the GCC version is displayed.


Use cwgwin

Http://www.cygwin.cn/site/install/

Recently, I wantLinuxA program on the machine is used in windows. Directly copy souwindowsrce codes to Windows and cannot be compiled using Windows C compiler. It is probably because some libraries are missing. Later, I thought that the files in Linux were compiled with ccgcc. Because of this, I think it would be worth a try if there is a Windows version or a ccgcc compiler.

I searched the internet for a long time, it seems that CC or GCC compiler. However, if cygwin , which can contain the GCC compiler. Cygwin I used it a year or two ago, but it is not very common. Go to the cygwin website and take a closer look. We found that cygwin indeed has GCC installed. Then download and install cygwin and GCC in cygwin environment. The GCC can be used to compile the source codes in Linux! Next I will introduce how to install cygwin and GCC in windows and how to use it.

1. Go to the cygwin website (Www.cygwin.comDownload an installation file (setup.exe)Www.cygwin.com/setup.exeThe file size is small, less than kb. Then run setup.exe in double steps. Because it is the first installation, you must choose to install it online from the Internet. You can also download the installation file from the Internet and then install it manually. I chose the latter, because in this way, I can install it in the future when it is not connected to the Internet.

2. Click "Next" and select a server that you think has the fastest network speed from the list of servers. Click "Next" to display the interface shown in, which is used to select the program you want to install.

If you do not make any changes, cygwin will be installed by default to run the minimum required programs and components. However, the GCC compiler is not listed in the default installer, so you must choose to install GCC. Specifically, expand the devel directory in the list in the above window, find the GCC-G ++ item, and click "default", it becomes "Install ", in addition, because of the dependency between programs, the GCC-core entry "default" is also changed to "Install ".

In addition, to enable GCC to correctly compile the source file, you must install the WIN32API library. Otherwise, compilation errors may occur. Therefore, you need to expand the libs directory in the preceding window, find WIN32API, and click it as "Install ".

3. wait patiently for the program to download the required installation file. Once downloaded, run setup.exe again. First, select the location where cygwin will be installed, and then select the hard disk location where the installation files you just downloaded are located. Then you need to install GCC and WIN32API again. In this way, you can start the installation.

4. Run cygwin after the installation is complete. In the window, you can directly use GCC for compilation by typing GCC. The executable file generated by the compilation chain is automatically suffixed with ".exe" and can be run directly in the cygwin environment. However, if you run the command in ms dos instead of cygwin, an error occurs. The solution is simple: copy the cygwin1.dll file to the C: \ Windows directory.


 

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.