在Windows下编译gcc4.5.1

知识废弃! 请参见http://www.cnblogs.com/xunxun1982/archive/2010/11/30/1892307.html

一、前期准备

1、安装msys类Linux shell环境,下载地址http://downloads.sourceforge.net/mingw/MSYS-1.0.11.exe,假设装在D:\msys\1.0下面,安装类Linux附加命令http://downloads.sourceforge.net/mingw/msysDTK-1.0.1.exe,也安装在D:\msys\1.0下面。

2、安装MinGW编译器,项目地址http://sourceforge.net/projects/mingw/,假设装在C:\MinGW下。

3、安装Gnuwin32,项目地址http://gnuwin32.sourceforge.net/,假设装在C:\GnuWin32。

 

以上的安装的bin目录都加入path系统变量。

 

二、目录结构

在msys和bin目录的同级建立mingw目录(作为gcc和第三方库的安装目录),具体放置如下:

msys

   |---1.0

          |---bin

          |---mingw

                   |---bin

                   |---include

                   |---lib

                   |---build

                           |---src

说明,以下下载的源码包都放到到build\src下面并解压,下载的补丁包都放到build下面。

此文需要的补丁请从我的Google code上下载,list地址为http://code.google.com/p/pcxprj/downloads/list,下载gcc4.5.1 patch,解压到build文件夹下面。

配置完后,运行msys环境。

 

三、安装第三方库(编译gcc4.5.1必须,顺序不能错)

       1、pthreads-w32

            版本2.9.0。

            下载链接:http://abechin.sakura.ne.jp/sblo_files/k-tai-douga/ffmpeg/pthreads-w32-2-9-0-release.tar.bz2

            进入pthreads目录,在msys输入以下命令

$ make clean GC-static
$ cp libpthreadGC2.a /mingw/lib/libpthread.a
$ cp pthread.h sched.h semaphore.h /mingw/include/.

     

      2、zlib

            版本1.2.5。

            下载链接:http://zlib.net/zlib-1.2.5.tar.gz

            进入zlib目录。

$ make -f win32/Makefile.gcc
$ cp libz.a /mingw/lib/
$ cp zlib.h zconf.h /mingw/include/

     3、libiconv

           版本1.13.1。

           下载链接:http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz

           进入libiconv目录。

$ patch -p1 < ../libiconv.patch
$ ./configure --prefix=/mingw --disable-shared --enable-static
$ make
$ make install

    4、GMP

           版本5.0.1。

           下载地址:ftp://ftp.gmplib.org/pub/gmp-5.0.1/gmp-5.0.1.tar.bz2

           进入GMP目录。

$ CPPFLAGS=-fexceptions ./configure --prefix=/mingw --enable-cxx
$ make
$ make install

  

   5、MPFR

          依赖GMP。

          版本3.0.0。

          下载地址:http://www.mpfr.org/mpfr-current/mpfr-3.0.0.tar.bz2

          进入MPFR目录。

$ patch -p1 < ../allpatches
$ ./configure --prefix=/mingw
$ make
$ make install

   6、MPC

          依赖GMP和MPFR。

          版本0.8.2。

          下载地址:http://www.multiprecision.org/mpc/download/mpc-0.8.2.tar.gz

          进入MPC目录。

$ ./configure --prefix=/mingw
$ make
$ make install

  7、PolyLib

         版本5.22.5。

         下载地址:http://icps.u-strasbg.fr/polylib/polylib_src/polylib-5.22.5.tar.gz

         进入PolyLib目录。

$ ./configure --prefix=/mingw
$ make
$ make install

   8、PPL

         依赖GMP。

         版本0.10.2(不要下载0.11版及以上的)。

         下载地址:ftp://ftp.cs.unipr.it/pub/ppl/releases/0.10.2/ppl-0.10.2.tar.bz2

         进入PPL目录。

$ ./configure --prefix=/mingw --disable-debugging
$ make
$ make install

  9、Cloog-ppl

         依赖PolyLib和PPL。

         版本0.15.9(不要下载0.15.10版及以上)。

         下载地址:ftp://gcc.gnu.org/pub/gcc/infrastructure/cloog-ppl-0.15.9.tar.gz

         进入cloog-ppl目录。

$ ./configure --prefix=/mingw --with-ppl --with-host-libstdcxx=-lstdc++
$ make
$ make install

 

四、编译gcc

1、下载包

     从ftp://ftp.dti.ad.jp/pub/lang/gcc/releases/gcc-4.5.1/下载以下3个包

 gcc-core-4.5.1.tar.bz2
gcc-g++-4.5.1.tar.bz2
gcc-fortran-4.5.1.tar.bz2

   解压到build\src目录下,得到gcc-4.5.1的目录。

   因为我们只编译C、C++ 和Fortran编译器,其他包可以不下。

 

2、补丁。

     进入gcc-4.5.1的目录。

$ patch -p1 < ../libgomp-pthreads.diff
$ patch -p1 < ../make-temp-file.diff   

 

    3、配置。

$ mkdir tmp
$ cd tmp
$ ../configure --prefix=/mingw --build=mingw32 --host=i686-pc-mingw32
--target=i686-pc-mingw32 --with-arch=i686 --with-tune=generic
--disable-shared --enable-languages=c,c++,fortran --enable-libgomp
--disable-werror --enable-threads --disable-nls --disable-win32-registry
--disable-sjlj-exceptions --with-dwarf2 --enable-lto --with-system-zlib
--with-host-libstdcxx=-lstdc++ --enable-libstdcxx-debug
--enable-cxx-flags='-fno-function-sections -fno-data-sections'
--disable-libstdcxx-pch --enable-version-specific-runtime-libs
--disable-bootstrap

    当然你也可以生成优化目标代码。

    下面三项看自己情形使用。

--with-arch=i686 --with-tune=generic
--with-arch=core2 --with-tune=core2
--with-arch=athlon64 --with-tune=athlon64

    注:中间无回车。

 

    4、编译及安装(在tmp目录下)。

$ make -j2 BOOT_CFLAGS="-O2 -D__USE_MINGW_ACCESS" 
CFLAGS="-O2 -D__USE_MINGW_ACCESS"
CXXFLAGS="-mthreads -O2"
LDFLAGS="-s"
$ make install

 

   注:中间无回车。

           到此,gcc4.5.1已经在/mingw下面安装完成,要使得gcc工作,还需要安装binutils和w32api。

 

五、编译binutils和windows api。

1、Binutils

    建议下CVS最新版。

    snapshots目录为ftp://sourceware.org/pub/binutils/snapshots

$ ./configure --prefix=/mingw
$ make
$ make install

2、w32api

    下载目录   http://sourceforge.net/downloads/mingw/MinGW/BaseSystem/RuntimeLibrary/Win32-API/

    编译安装同上。

 

3、MinGW Runtime

    下载目录http://sourceforge.net/downloads/mingw/MinGW/BaseSystem/RuntimeLibrary/MinGW-RT/

    编译安装同上。

   

六、后记

     经过以上步骤,编译成功了gcc4.5.1(编译器+基本库),一个是用保守配置编译的(MinGW gcc4.5.1 for generic.7z),一个是开启酷睿2优化编译的(MinGW gcc4.5.1 for Core2.7z),包含了4.5.1的基本特性(参见http://gcc.gnu.org/gcc-4.5/changes.html,中文参考http://www.lingcc.com/2010/04/16/10746/),编译器有C、C++、Fortran三种(ada,java,objc(++)等因为我不用没有编译),加入了链接时优化选项(-flto,默认不开启),
同时加入了Graphite循环体构造优化(默认不开启)。
     项目地址为http://code.google.com/p/pcxprj,选择Downloads栏目,gdb是从cvs上拖的7.2.50.20100831,请在上面另外下载。
     欢迎大家下载测试 。

posted on 2010-08-31 22:27  PcX  阅读(4675)  评论(4编辑  收藏  举报

导航