Windows下的MinGW 的安装和配置

MinGW 是一个可自由使用和自由发布的Windows特定头文件和使用GNU工具集导入库的集合,允许你在GNU/Linux和Windows平台生成本地的Windows程序而不需要第三方C运行时库。这个和Cygwin(面向POSIX标准)是不同的。

本示例用的版本:mingw-x32-gcc-4.8.1-posix-dwarf-rev2
下载地址:[url]http://download.csdn.net/detail/u011669055/6317573[/url]

老旧的经典版本:mingw 5.1.6 with gcc 3.4.5
下载地址:[url]http://www.pc6.com/softview/SoftView_56757.html[/url]

最新的可到官网下载:[url]http://www.mingw.org/[/url]

直接解压安装即可,建议安装到 C:\mingw目录,方便使用。

完毕,再设置环境变量。为了方便和移植,我们创建一个mingw-env.bat,内容如下:
@echo off
[b]set MINGW_HOME=C:\MinGW[/b]
set C_INCLUDE_PATH=%MINGW_HOME%\include;
set CPLUS_INCLUDE_PATH=%MINGW_HOME%\lib\gcc\i686-w64-mingw32\4.8.1;%MINGW_HOME%\lib\gcc\i686-w64-mingw32\4.8.1\include;%MINGW_HOME%\lib\gcc\i686-w64-mingw32\4.8.1\include\c++;%MINGW_HOME%\lib\gcc\i686-w64-mingw32\4.8.1\include\c++\backward;%MINGW_HOME%\include;
set LIBRARY_PATH=%MINGW_HOME%\lib;
set PATH=%MINGW_HOME%\bin;%MINGW_HOME%\i686-w64-mingw32\lib;%PATH%;
echo *** MinGW ENV SET OK ***
@echo on

当然,你也可以不使用bat,直接设置系统或用户的环境变量也可,这里不再赘述。
如果你的mingw不是安装到默认的C:\MinGW目录,请修改MINGW_HOME的指向。

接着桌面创建一个快捷方式,目标设置为:C:\Windows\System32\cmd.exe /K C:\mingw\mingw-env.bat 这样,后面直接双击这个快捷方式即可进入mingw的命令窗口环境,十分方便。

最后进行下面三项测试,看看环境是否工作正常:
1、gcc -v

2、gcc -o hello1.exe hello1.c

#include <stdio.h>
int main( int argc, char *argv[] )
{
printf( "Hello World!\n" );
return 0;
}

3、g++ -o hello2.exe hello2.cpp

#include <iostream>
using namespace std;
int main( int argc, char *argv[] )
{
cout << "Hello World!" << endl;
return 0;
}


*** 附:MinGW的官方介绍 ***
[b]MinGW[/b], a contraction of "Minimalist GNU for Windows", is a minimalist development environment for native Microsoft Windows applications.

[b]MinGW[/b] provides a complete Open Source programming tool set which is suitable for the development of native MS-Windows applications, and which do not depend on any 3rd-party C-Runtime DLLs. (It does depend on a number of DLLs provided by Microsoft themselves, as components of the operating system; most notable among these is MSVCRT.DLL, the Microsoft C runtime library. Additionally, threaded applications must ship with a freely distributable thread support DLL, provided as part of MinGW itself).

[b]MinGW[/b] compilers provide access to the functionality of the Microsoft C runtime and some language-specific runtimes. [b]MinGW[/b], being Minimalist, [i]does not, and never will, attempt to provide a POSIX runtime environment for POSIX application deployment on MS-Windows[/i]. If you want POSIX application deployment on this platform, please consider [b]Cygwin [/b]instead.

Primarily intended for use by developers working on the native MS-Windows platform, but also available for cross-hosted use, (see note below -- you may need to follow the "read more" link to see it), MinGW includes:
A port of the GNU Compiler Collection (GCC), including C, C++, ADA and Fortran compilers;
GNU Binutils for Windows (assembler, linker, archive manager)
A command-line installer, with optional GUI front-end, (mingw-get) for MinGW and MSYS deployment on MS-Windows
A GUI first-time setup tool (mingw-get-setup), to get you up and running with mingw-get.

[b]MSYS[/b], a contraction of "Minimal SYStem", is a Bourne Shell command line interpreter system. Offered as an alternative to Microsoft's cmd.exe, this provides a general purpose command line environment, which is particularly suited to use with MinGW, for porting of many Open Source applications to the MS-Windows platform; a light-weight fork of Cygwin-1.3, it includes a small selection of Unix tools, chosen to facilitate that objective.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值