`
dbaspider
  • 浏览: 257137 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

Windows下的MinGW 的安装和配置

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

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

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

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

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

完毕,再设置环境变量。为了方便和移植,我们创建一个mingw-env.bat,内容如下:
@echo off
set MINGW_HOME=C:\MinGW
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的官方介绍 ***
MinGW, a contraction of "Minimalist GNU for Windows", is a minimalist development environment for native Microsoft Windows applications.

MinGW 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).

MinGW compilers provide access to the functionality of the Microsoft C runtime and some language-specific runtimes. MinGW, being Minimalist, does not, and never will, attempt to provide a POSIX runtime environment for POSIX application deployment on MS-Windows. If you want POSIX application deployment on this platform, please consider Cygwin 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.

MSYS, 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.
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics