现在的位置: 首页 > 综合 > 正文

编译MinGW版GCC

2013年03月27日 ⁄ 综合 ⁄ 共 12409字 ⁄ 字号 评论关闭

I've made this little guide to get a working MinGW gcc-4.0.3 up to gcc-4.1.2 (should work with binutils too)

i did have the latest build on my googlepage but it ran out of bandwidth, unless anybody canrecommend a freehost - its back to the previous way

try this (check http://www.mingw.org/download.shtml for updates)

MinGW-5.1.3-[candidate only base-files]

http://prdownloads.sf.net/mingw/MinG...3.exe?download

MSYS-1.0.10.exe

http://prdownloads.sf.net/mingw/MSYS...0.exe?download

if you need cvs
http://prdownloads.sf.net/mingw/msys...1.exe?download

and when installing if the connection drops, click retry (sf problem)

and i recommend to get latest runtime,w32api headers
http://sourceforge.net/project/showf...ease_id=158844
http://sourceforge.net/project/showf...ease_id=158847

and the new binutils that allows spaces in filenames
https://sourceforge.net/forum/forum.php?forum_id=661143

and if building hogs your system i recommend editing the msys.bat

change the:
line 62: start rxvt ... into start /LOW rxvt ... and
line 66: start sh ... into start /LOW sh ...
(more reliable for your system, you can do other while building)

get gcc-sources try here:
http://www.mirrorservice.org/sites/s...t.com/pub/gcc/

release directory or whatever

***** most of the pre-released/snapshots of gcc needs bison,flex and sometimes libiconv, libtool

bison into /mingw/ directory --
http://gnuwin32.sourceforge.net/down...on-bin-zip.php
http://gnuwin32.sourceforge.net/down...on-dep-zip.php

flex into /mingw/ directory --
http://gnuwin32.sourceforge.net/down...ex-bin-zip.php

libtool into /mingw/ directory --
http://gnuwin32.sourceforge.net/down...ol-bin-zip.php

libiconv into /mingw/
http://gnuwin32.sourceforge.net/down...nv-bin-zip.php
http://gnuwin32.sourceforge.net/down...nv-dep-zip.php

and maybe newer gnu-make (not needed but useful and sometimes buggy)
http://prdownloads.sourceforge.net/m...3.exe?download

installing the newer make delete/rename old msys/1.0/bin/make.exe and install the new make into /mingw/ and then
rename the new mingw32-make.exe into make.exe

make --version to check

or compile your own from http://ftp.gnu.org/gnu/make/

***

The directory that should contain system headers does not exist:
/usr/include

create an empty include folder in /msys/1.0/

***

make[2]: Leaving directory `/home/user/svn/gcc-4_1-branch/build/libcpp'
make[2]: Entering directory `/home/user/svn/gcc-4_1-branch/build/gcc'
Makefile:1280: *** target pattern contains no `%'. Stop.
make[2]: Leaving directory `/home/user/svn/gcc-4_1-branch/build/gcc'
make[1]: *** [all-gcc] Error 2
make[1]: Leaving directory `/home/user/svn/gcc-4_1-branch/build'
make: *** [all] Error 2

check makefile = LD = ld
(not LD = ?:/mingw/bin/../lib/gcc/mingw32/???/../../../../mingw32/bin/ld.exe)
i think related to --with-gcc --with-gnu-ld --with-gnu-as

or delete ld.exe from /mingw/mingw32/bin or empty the folder that's what i did
(but i think the newer binutils fixes that anyway, will check later)

****

Step 1

cd yourgcc-src
mkdir build
cd build

Step 2
tip. before you install new gcc zip your /mingw/ directory ... you never know

Pass 1

append "&> output-results.txt" without quotes to echo to file (displayed text into a file)

after some experiments, i found symbolic links are broke, not sure on how to fix it

you can append: --with-dwarf2 -s (for silent output) to configure line
you can append &>result.txt to pipe any shell output to file

*** for gcc 4.1+ use bison,flex see notes on ld.exe

*** for gcc 4.2+ append --disable-werror

*** updated configure 2006.12.23 (remove --host=mingw32 --target=mingw32 to build for your system)

(remove '"CFLAGS=-O2" "LDFLAGS=-s" --enable-optimize' if debugging the compiler)

for i386

Quote:
../configure --enable-languages=c -v --enable-optimize --host=mingw32 --build=mingw32 --target=mingw32 --prefix=/mingw --oldincludedir=/mingw/include --enable-threads --disable-nls --disable-win32-registry --disable-shared --without-x

for i686

Quote:
../configure --enable-languages=c -v --enable-optimize --prefix=/mingw --oldincludedir=/mingw/include --enable-threads --disable-nls --disable-win32-registry --disable-shared --without-x

Quote:
make "CFLAGS=-O2" "LDFLAGS=-s"

or

Quote:
make bootstrap "CFLAGS=-O2" "LDFLAGS=-s"

* if the bootstrap fails something is wrong with gcc compiler itself, means it can't rebuild itself with itself

(you can save it for later, if you re-install mingw just copy the folder back in)

Quote:
make DESTDIR=/home/gcc-build install

(the normal install)

Quote:
make install
Quote:
make html

(if you want the html - docs, there should be here yourgcc-src/libstdc++-v3/docs/html )

close and re-load ming

Step 3

Pass 2

empty your build directory

if you need g77 its not supported in gcc 4+, try gcc 3.4.4
but if want to build gfortran read further down

available languages are: c,c++,f95,java,objc,obj-c++,treelang

*** for gcc 4.2+ append --disable-werror

for i386

Quote:
../configure --enable-languages=c,c++ -v --enable-optimize --host=mingw32 --build=mingw32 --target=mingw32 --prefix=/mingw --oldincludedir=/mingw/include --enable-threads --disable-nls --disable-win32-registry --disable-shared --without-x

for i686

Quote:
../configure --enable-languages=c,c++ -v --enable-optimize --prefix=/mingw --oldincludedir=/mingw/include --enable-threads --disable-nls --disable-win32-registry --disable-shared --without-x

Quote:
make "CFLAGS=-O2" "LDFLAGS=-s"

or

Quote:
make bootstrap "CFLAGS=-O2" "LDFLAGS=-s"

* if the bootstrap fails something is wrong with gcc compiler itself, means it can't rebuild itself with itself

(you can save it for later, if you re-install mingw just copy the folder back in)

Quote:
make DESTDIR=/home/gcc-build install

(the normal install)

Quote:
make install

close and re-load ming

Step 4

Pass 3 ( build gcc with gcc with profiled bootstrap to get a faster compiler)
this not necessary but you get a faster compiler

empty your build directory

for i386

Quote:
../configure --enable-languages=c,c++ -v --enable-optimize --host=mingw32 --build=mingw32 --target=mingw32 --prefix=/mingw --oldincludedir=/mingw/include --enable-threads --disable-nls --disable-win32-registry --disable-shared --without-x

for i686

Quote:
../configure --enable-languages=c,c++ -v --enable-optimize --prefix=/mingw --oldincludedir=/mingw/include --enable-threads --disable-nls --disable-win32-registry --disable-shared --without-x

Quote:
make "CFLAGS=-O2" "LDFLAGS=-s"

or

Quote:
make bootstrap "CFLAGS=-O2" "LDFLAGS=-s"

* if the bootstrap fails something is wrong with gcc compiler itself, means it can't rebuild itself with itself

(you can save it for later, if you re-install mingw just copy the folder back in)

Quote:
make DESTDIR=/home/gcc-build install

(the normal install)

Quote:
make install

***

Fortran, GMP, MPFR

Building GMP

download gmp from
http://www.mirrorservice.org/sites/ftp.gnu.org/gnu/gmp/

cd your gmp-src

Quote:
./configure --host=mingw32 --build=mingw32 --target=mingw32 --prefix=/mingw
Quote:
make DESTDIR=/home/gcc-libs install
Quote:
make install

Building MPFR

download mpfr from
http://www.mpfr.org/mpfr-current/

cd your mpfr-src

Quote:
./configure --host=mingw32 --build=mingw32 --target=mingw32 --prefix=/mingw
Quote:
make DESTDIR=/home/gcc-libs install
Quote:
make install

Building Fortran (F95)

cd your gcc-src
mkdir build
cd build

Quote:
../configure --enable-languages=f95 -v --enable-optimize --prefix=/mingw --oldincludedir=/mingw/include --enable-threads --disable-nls --disable-win32-registry --disable-shared --without-x

Quote:
make "CFLAGS=-O2 " "LDFLAGS=-s"

or

Quote:
make bootstrap "CFLAGS=-O2" "LDFLAGS=-s"

(save for later installs)

Quote:
make DESTDIR=/home/f95-build install
Quote:
make install

**** more to add later

Compiling GCC for MinGW from Linux

the 3 types
build - is the system you are running it on
host - is the system you will run it on
target - is the system the compiler will create code for

the source codes are the same look above for links

needed extra tools: bison,flex,libtool,texinfo(makeinfo) maybe needed automake,autogen,autoconf

you can instead of step 3, do this for the gmp/mpfr

(default prefix is /usr/local)

Quote:
./configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --disable-shared

(can use -march='your-cpu' in cflags eg. -march=k8)

Quote:
make CFLAGS="-O3 -m32" CXXFLAGS="${CFLAGS}" LDFLAGS="-s"
make check
sudo make install && make distclean

Step 1 : binutils linux

Quote:
sudo mkdir -m 777 /my-toolchain
Quote:
cd your-binutils/build
Quote:
../configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=i686-pc-linux-gnu --disable-nls --prefix=/my-toolchain

(can use -m32 -march='your-cpu' in cflags eg. -march=k8)

Quote:
make CFLAGS="-O2 -m32" CXXFLAGS="${CFLAGS}" LDFLAGS="-s"
make DESTDIR=/home/user/mytools/linux-binutils-build install
make install && rm -rf *

Step 2 : gcc linux

Quote:
PATH=/my-toolchain/bin:$PATH
Quote:
cd your-gcc/build
Quote:
../configure --enable-__cxa_atexit --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=i686-pc-linux-gnu --enable-languages=c,c++ --disable-nls --prefix=/my-toolchain

(using bootstrap re-compile gcc with the gcc it has just made - you get a faster compiler, and it checks for errors)
(can use -march='your-cpu' in cflags eg. -march=k8)

Quote:
make CFLAGS="-O2 -m32" CXXFLAGS="${CFLAGS}" LDFLAGS="-s"
make DESTDIR=/home/user/mytools/linux-build install
make install && rm -rf *

Step 3 : gmp & mpfr linux

do this step in gmp & mpfr src folders

Quote:
./configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --disable-shared --prefix=/my-toolchain

(can use -march='your-cpu' in cflags eg. -march=k8)

Quote:
make CFLAGS="-O3 -m32" CXXFLAGS="${CFLAGS}" LDFLAGS="-s"
make check
make DESTDIR=/home/user/mytools/linux-libs install
make install && make distclean

repeat steps 1&2, if you like

Step 4 : binutils cross linux>mingw

Quote:
sudo mkdir -m 777 /cc-mingw
Quote:
cd your-binutils/build
Quote:
../configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=i686-pc-mingw32 --disable-nls --prefix=/cc-mingw
make CFLAGS="-O2 -m32" CXXFLAGS="${CFLAGS}" LDFLAGS="-s"
make DESTDIR=/home/user/mytools/linux-cross-binutils-build install
make install && rm -rf *

Step 5 : setup mingw32 includes & libs

Quote:
sudo mkdir -m 777 /mingw/include

extract mingw-runtime & w32-api to below path :
/home/user/my-gcc/mingw-libs/headers/

copy all includes & libs into /cc-mingw/i686-pc-mingw32

cp -r /home/user/my-gcc/mingw-libs/headers/* /cc-mingw/i686-pc-mingw32

Step 6 : gcc cross linux>mingw

Quote:
PATH=/cc-mingw/bin:$PATH
Quote:
cd your-gcc/build
Quote:
../configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=i686-pc-mingw32 --enable-languages=c,c++ --disable-nls --prefix=/cc-mingw

(using bootstrap re-compile gcc with the gcc it has just made - you get a faster compiler, and it checks for errors)
(can use -march='your-cpu' in cflags eg. -march=k8)

Quote:
make CFLAGS="-O2 -m32" CXXFLAGS="${CFLAGS}" LDFLAGS="-s"
make DESTDIR=/home/user/mytools/linux-cross-gcc-build install
make install && rm -rf *

Step 7 : gmp & mpfr - cross linux>mingw - if this is not done, gcc will not find gmp & mpfr as it needs mingw versions

Quote:
./configure --build=i686-pc-linux-gnu --host=i686-pc-mingw32 --disable-shared --prefix=/cc-mingw/i686-pc-mingw32
make CFLAGS="-O3 -m32" CXXFLAGS="${CFLAGS}" LDFLAGS="-s"

(can't check when crossing-compiling)
(make backup)

Quote:
make DESTDIR=/home/user/cc-mingw32-libs install
Quote:
make install && make distclean

Step 8 : mingw pthreads

extract pthreads-win32 (src: ftp://ftp.mirrorservice.org/sites/so...dll-latest.tar)

rename libpthreadGC2.a into libthread.a & copy into /home/user/my-gcc/mingw-libs/headers/lib
copy pthread.h sched.h semaphore.h into /home/user/my-gcc/mingw-libs/headers/include

Step 9 : gcc-mingw ... final build

steps 1-8 only need doing once

(if paths not set)
PATH=/cc-mingw/bin:/my-toolchain/bin:$PATH

(you can use --program-suffix=-gcc.number
make sure all mingw include & libs are in /mingw/i686-pc-mingw32 ... for libgomp see step 10)

Quote:
cd your-gcc/build
Quote:
../configure --host=i686-pc-mingw32 --build=i686-pc-linux-gnu --target=i686-pc-mingw32 --enable-languages=c,c++ --prefix=/mingw --enable-threads=win32 --disable-nls --disable-win32-registry --disable-shared --without-x

(can use -march='your cpu' in cflags eg. -march=k8)

Quote:
make CFLAGS="-O2 -m32" CXXFLAGS="${CFLAGS}" LDFLAGS="-s"
Quote:
make DESTDIR=/home/user/cc-mingw32-gcc-build-i686 install && rm -rf *

Step 10: libgomp (openmp)

Quote:
cd your-gcc/build
Quote:
(libgomp needs pthreads-win32)
../libgomp/configure --host=i686-pc-mingw32 --build=i686-pc-linux-gnu --target=i686-pc-mingw32 --prefix=/mingw --enable-threads=win32 --disable-nls --disable-win32-registry --disable-shared --without-x
Quote:
make DESTDIR=/home/user/cc-mingw32-gcc-build-i686 install && rm -rf *

transfer that folder to windows (or tar.bz2 it)

**** more to add later

 

MinGW 是 GCC编译器最受欢迎可产生原生Win32程序的变种。MinGW的核心是GCC编译器,但是MinGW官方更新的速度真的不敢恭维,现在还停留在3.x.x时代!下边,我们结合老外的 《Compiling GCC for MinGW》 一文谈谈如何自行编译MinGW版GCC,让我们跟上时代潮流!

一、工具准备

与其事必先利其器,我们首先需要准备一些工具。他们是:

一个可以工作的MinGW版GCC编译器
MinGW
MSYS
MSYSDTK
mingw-runtime
windows api
bison
bison-dep
flex
mingw32-make
(重命名原来的make.exe,将新下载的mingw32-make.exe更名为make.exe。)

这些工具您都可以在http://www.mingw.org/download.shtml 找到相应的下载位置,如果您需要编译一大堆GCC编译器(GCC 支持多种编程语言),建议您修改msys.bat :

62行::start rxvt ... 改为 start /LOW rxvt ...
66行: start sh ... 改为 start /LOW sh ...

GCC的源码树可以在 http://gcc.gnu.org/mirrors.html 找一个就近的镜像服务器下载。

二、准备目录

解压缩您的GCC源代码
建立build目录
进入build目录

三、编译步骤

../configure --enable-languages=c,c++ -v --enable-optimize --host=mingw32 --target=mingw32 --prefix=/mingw --oldincludedir=/mingw/include --enable-threads --disable-nls --disable-win32-registry --disable-shared --without-x

make bootstrap "CFLAGS=-O2 -fssa" "LDFLAGS=-s"
make
make profiledbootstrap
如果编译bootsrtap失败,可以尝试使用
make DESTDIR=/home/gcc-build install
通常情况下可以使用
make install 进行安装
如果您需要GCC文档,可以使用下面的指令
make html
完成后,关闭MinGW即可。

Google

抱歉!评论已关闭.