参考官方文档http://www.mingw.org/wiki/InstallationHOWTOforMinGW
其上面有链接,只有少部分链接无效。这个版本是基于gcc4.5的
总共下载到如下文件,包含gcc,g++和gdb调试程序等
binutils-2.20.51-1-mingw32-bin.tar.lzma
gcc-c++-4.5.0-1-mingw32-bin.tar.lzma
gcc-core-4.5.0-1-mingw32-bin.tar.lzma
gdb-7.2-1-mingw32-bin.tar.lzma
gmp-5.0.1-1-mingw32-dev.tar.lzma
libexpat-2.0.1-1-mingw32-dll-1.tar.gz
libgcc-4.5.0-1-mingw32-dll-1.tar.lzma
libgmp-5.0.1-1-mingw32-dll-10.tar.lzma
libgomp-4.5.0-1-mingw32-dll-1.tar.lzma
libmpc-0.8.1-1-mingw32-dll-2.tar.lzma
libmpfr-2.4.1-1-mingw32-dll-1.tar.lzma
libpthread-2.8.0-3-mingw32-dll-2.tar.lzma
libssp-4.5.0-1-mingw32-dll-0.tar.lzma
libstdc++-4.5.0-1-mingw32-dll-6.tar.lzma
make-3.82-3-mingw32-bin.tar.lzma
mingwrt-3.18-mingw32-dev.tar.gz
mingwrt-3.18-mingw32-dll.tar.gz
mpc-0.8.1-1-mingw32-dev.tar.lzma
mpfr-2.4.1-1-mingw32-dev.tar.lzma
pthreads-w32-2.8.0-3-mingw32-dev.tar.lzma
w32api-3.15-1-mingw32-dev.tar.lzma
用7zip解压后(不得不承认lzma的压缩效率)
binutils-2.20.51-1-mingw32-bin.tar libssp-4.5.0-1-mingw32-dll-0.tar
gcc-c++-4.5.0-1-mingw32-bin.tar libstdc++-4.5.0-1-mingw32-dll-6.tar
gcc-core-4.5.0-1-mingw32-bin.tar make-3.82-3-mingw32-bin.tar
gdb-7.2-1-mingw32-bin.tar mingwrt-3.18-mingw32-dev.tar
gmp-5.0.1-1-mingw32-dev.tar mingwrt-3.18-mingw32-dev.tar.gz
libexpat-2.0.1-1-mingw32-dll-1.tar.gz mingwrt-3.18-mingw32-dll.tar
libgcc-4.5.0-1-mingw32-dll-1.tar mingwrt-3.18-mingw32-dll.tar.gz
libgmp-5.0.1-1-mingw32-dll-10.tar mpc-0.8.1-1-mingw32-dev.tar
libgomp-4.5.0-1-mingw32-dll-1.tar mpfr-2.4.1-1-mingw32-dev.tar
libmpc-0.8.1-1-mingw32-dll-2.tar pthreads-w32-2.8.0-3-mingw32-dev.tar
libmpfr-2.4.1-1-mingw32-dll-1.tar w32api-3.15-1-mingw32-dev.tar
libpthread-2.8.0-3-mingw32-dll-2.tar
两次解压后,得到如下如下目录(最好统一解压,第一次分开解压出现错误,可能是某些文件漏解压了吧)
D:\Program\MinGW>ls
bin dist doc include lib libexec lzma mingw32 share
为了方便起见,我通过bat文件设置环境变量(参考devcpp中的设置)
内容如下
@echo off
set MinGW_PATH=D:\Program\MinGW
path = %path%;%MinGW_PATH%\bin;%MinGW_PATH%\mingw32\bin
set LIBRARY_PATH=%MinGW_PATH%\lib
set C_INCLUDE_PATH=%MinGW_PATH%\include
set CPLUS_INCLUDE_PATH=%MinGW_PATH%\include;%MinGW_PATH%\include\c++\4.5.0;%MinGW_PATH%\include\c++\4.5.0\backward;%MinGW_PATH%\include\c++\4.5.0\mingw32;%MinGW_PATH%\lib\gcc\mingw32\4.5.0\include
注意对于不同的版本,你可能要修改些数字。
测试版本结果
C:\Users\Cherish>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=d:/program/mingw/bin/../libexec/gcc/mingw32/4.5.0/lto-wrappe
r.exe
Target: mingw32
Configured with: ../gcc-4.5.0/configure --enable-languages=c,c++,ada,fortran,obj
c,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgo
mp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-r
untime-libs --disable-werror --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.5.0 (GCC)
编译一个基本的HelloWorld程序
出现
Info: resolving std::cout by linking to __imp___ZSt4cout (auto-import)
c:/mingw/bin/../lib/gcc/mingw32/4.5.0/http://www.cnblogs.com/http://www.cnblogs.com/mingw32/bin/ld.exe: warning: a
uto-importing has been activated without --enable-auto-import specified on the c
ommand line.
This should work unless it involves constant data structures referencing symbols
from auto-imported DLLs.)
找到如下解答,显示编译需要为
g++ -Wl,--enable-auto-import test.cpp
才能将waring去除--不知道该如何从程序上消除这个警告(从新封装下gcc?)。
http://wiki.wxwidgets.org/HowTo:_Install_MSYS_and_MinGW_for_use_with_Eclipse_CDT
Note on usage of gcc/g++: Please read this article on the --enable-auto-import linker option for a good understanding of why you might be getting the following (or similar) warning, and decide whether you want to --enable-auto-import by default.
Info: resolving std::cout by linking to __imp___ZSt4cout (auto-import) c:/mingw/bin/../lib/gcc/mingw32/4.5.0/http://www.cnblogs.com/http://www.cnblogs.com/mingw32/bin/ld.exe: warning: a uto-importing has been activated without --enable-auto-import specified on the c ommand line. This should work unless it involves constant data structures referencing symbols from auto-imported DLLs.)
Enabling auto-import:
- in g++, the command line option is -Wl,--enable-auto-import to pass the argument to the linker (same option to be used for Eclipse linker call!)
- if the linker is called separately, the option should be just --enable-auto-import (not tested)
据说GCC4.5实现了某些C++0x的功能,可以在上面做些测试了,激动中。哈哈!
不过,这篇文章记录也没有任何技术含量,只是为了记录而记录。