Log in

View Full Version : Compiling GCC for MinGW & Cross-Compiling with Linux


Pages : 1 2 3 4 [5]

LoRd_MuldeR
11th April 2009, 13:28
cc979:
A build of the latest gcc 4.3.3 would be greatly appreciated. thanks.

Have a look here:
http://www.tdragon.net/recentgcc/

cc979
3rd August 2009, 16:10
Tested with Ubuntu 9.04 64 bit, 2009/08/03


building whole toolchain - binutils,gcc & cross binutils,gcc (updated 2009/08/03 for 64 bit linux host, needs update for mingw64)

using libc6-dev-i386(for 64 bit ubuntu hosts)
using bisonc++, flex, libtool, texinfo(makeinfo) maybe needed automake, autogen, autoconf

with sources from:
ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/
ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/binutils/
http://gmplib.org/
http://www.mpfr.org/
http://sourceforge.net/projects/mingw/files/ MinGW API for MS-Windows(dev) & MinGW Runtime(dev)
ftp://ftp.mirrorservice.org/sites/sources.redhat.com/pub/pthreads-win32/ (latest prebuilt)

*** alter x86_64-linux-gnu to i386-linux-gnu for 32 bit hosts

*** step 1 : initial gmp & mpfr linux

sudo mkdir -m 777 /my-toolchain

(do this step in gmp & mpfr src folders)

* for gmp
./configure --prefix=/my-toolchain --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu

* for mpfr
./configure --with-gmp=/my-toolchain/ --prefix=/my-toolchain --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu

make

make check -s

(make back-up)
make DESTDIR=/home/user/mytools/linux-libs install

make install && make distclean


*** step 2 : initial gcc linux

(from GCC docs, GCC has code to correctly determine the correct value for target for nearly all native systems. Therefore, we highly recommend you not provide a configure target when configuring a native compiler.)

(for 32 bit hosts, --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu)
(for 64 bit hosts, --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu)

(libc6-dev-i386 needed or --disable-multilib or setenv CFLAGS=-m64 added to fix /usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory)

(cd gcc/mybuild)

(remove --disable-libgomp if needed)

../configure --disable-libgomp --with-gmp=/my-toolchain/ --with-mpfr=/my-toolchain/ --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-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, later versions of gcc do this automatic)
(bootstrapping may fail on some systems)

make

(make back-up)
make DESTDIR=/home/user/mytools/linux-gcc-build install

make install && rm -rf *

PATH=/my-toolchain/bin:$PATH

*** step 2a : gmp & mpfr linux - redo if needed, other skip to step 3

(do this step in gmp & mpfr src folders)

* for gmp
./configure --prefix=/my-toolchain --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu

* for mpfr
./configure --with-gmp=/my-toolchain/ --prefix=/my-toolchain --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu

make

make check -s

(make back-up)
make DESTDIR=/home/user/mytools/linux-libs install

make install && make distclean

*** step 2b : setup gcc linux - redo (if needed, otherwise skip to step 3)

(cd gcc/mybuild)

(remove --disable-libgomp if needed)

../configure --disable-libgomp --with-gmp=/my-toolchain/ --with-mpfr=/my-toolchain/ --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --enable-languages=c,c++ --disable-nls --prefix=/my-toolchain

make LDFLAGS="-s" bootstrap

(make back-up)
make DESTDIR=/home/user/mytools/linux-gcc-build install

make install && rm -rf *


*** step 3 : binutils linux

(cd binutils/mybuild)

../configure --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --disable-nls --prefix=/my-toolchain

make

(make back-up)
make DESTDIR=/home/user/mytools/linux-binutils-build install

make install && rm -rf *


*** step 4 : gcc linux (redo if needed, otherwise skip to step 5)

(cd gcc/mybuild)

(remove --disable-libgomp if needed)

../configure --disable-libgomp --with-gmp=/my-toolchain/ --with-mpfr=/my-toolchain/ --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --enable-languages=c,c++ --disable-nls --prefix=/my-toolchain

make

(make back-up)
make DESTDIR=/home/user/mytools/linux-gcc-build install

make install && rm -rf *


*** step 5 : binutils cross linux>mingw

sudo mkdir -m 777 /cc-mingw

(cd binutils/mybuild)

../configure --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=i686-pc-mingw32 --disable-nls --prefix=/cc-mingw

make LDFLAGS="-s"

(make back-up)
make DESTDIR=/home/user/mytools/linux-cross-binutils-build install

make install && rm -rf *


*** step 6 : setup mingw32 includes & libs

sudo mkdir -m 777 /mingw && mkdir /mingw/include

extract includes & libs from mingw-runtime & w32-api to below path, or alter to needs :
/home/user/gcc/mingw-libs/headers/

extract pthreads-win32 (src: ftp://ftp.mirrorservice.org/sites/sources.redhat.com/pub/pthreads-win32/dll-latest.tar)

copy & rename libpthreadGC2.a into libthread.a copy into /home/user/my-gcc/mingw-libs/headers/lib, which is the safer exeception handler but may change
copy pthread.h sched.h semaphore.h into /home/user/my-gcc/mingw-libs/headers/include

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


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


** step 7 : gcc cross linux>mingw

PATH=/cc-mingw/bin:$PATH

(cd gcc/mybuild)

(remove --disable-libgomp if needed)

../configure --disable-libgomp --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=i686-pc-mingw32 --enable-languages=c,c++ --disable-nls --prefix=/cc-mingw

make

(make back-up)
make DESTDIR=/home/user/mytools/linux-cross-gcc-build install

make install && rm -rf *


*** step 8 : gmp & mpfr - cross linux>mingw - if this is not done, gcc will not find correct gmp & mpfr as it needs mingw versions

(do this step in gmp & mpfr src folders)

./configure --build=x86_64-linux-gnu --host=i686-pc-mingw32 --disable-shared --prefix=/cc-mingw/i686-pc-mingw32

make

(can't make check when crossing-compiling)
(make backup)
make DESTDIR=/home/user/cc-mingw32-libs install

make install && make distclean


*** step 9 : libgomp - cross linux>mingw (skip if not needed, it can cause problems on final cross-compile)

(cd gcc/mybuild)
../libgomp/configure --host=i686-pc-mingw32 --build=x86_64-linux-gnu --target=i686-pc-mingw32 --prefix=/cc-mingw/i686-pc-mingw32 --enable-sjlj-exceptions --enable-threads=win32 --disable-nls --disable-win32-registry --disable-shared --without-x

make LDFLAGS="-s"

(make back-up)
make DESTDIR=/home/user/cc-mingw32-libs install

make install && rm -rf *


*** step 10 : final target gcc-mingw

steps 1-9 only need doing once, as back-ups can used after copying into correct places

(if paths not set)

PATH=/my-toolchain/bin:$PATH
PATH=/cc-mingw/bin:$PATH

or

PATH=/cc-mingw/bin:/my-toolchain/bin:$PATH

(cd gcc/mybuild)

(make sure all mingw include & libs are in /mingw/i686-pc-mingw32 ... see steps 6 to 9)

**** pick one

(--host=i686-pc-mingw32 --build=x86_64-pc-linux-gnu --target=i686-pc-mingw32, disable shared with libgomp otherwise you may find libgomp creates wrong lib)

../configure --program-suffix=-4.4 --prefix=/mingw --with-local-prefix=/mingw --host=i686-pc-mingw32 --build=x86_64-pc-linux-gnu --target=i686-pc-mingw32 --disable-shared --enable-libgomp --enable-languages=c,c++ --disable-nls --disable-werror --disable-win32-registry --enable-sjlj-exceptions --enable-threads=win32 --disable-libstdcxx-pch --enable-fully-dynamic-string --with-tune=generic --enable-version-specific-runtime-libs

(make with stripped symbols)
make LDFLAGS="-s"

// final output for windows

**** pick one

make DESTDIR=/home/user/cc-mingw32-gcc-build-i686 install && rm -rf *

make DESTDIR=/home/user/cc-mingw32-gcc-3.4.6-build-i686 install && rm -rf *
make DESTDIR=/home/user/cc-mingw32-gcc-4.0.4-build-i686 install && rm -rf *
make DESTDIR=/home/user/cc-mingw32-gcc-4.1.2-build-i686 install && rm -rf *
make DESTDIR=/home/user/cc-mingw32-gcc-4.2.1-sjlj-build-i686 install && rm -rf *
make DESTDIR=/home/user/cc-mingw32-gcc-4.2.1-dw2-build-i686 install && rm -rf *
make DESTDIR=/home/user/cc-mingw32-gcc-4.2.2-sjlj-build-i686 install && rm -rf *
make DESTDIR=/home/user/cc-mingw32-gcc-4.2.2-dw2-build-i686 install && rm -rf *
make DESTDIR=/home/user/cc-mingw32-gcc-4.2.3-sjlj-suffix-build-i686 install && rm -rf *
make DESTDIR=/home/user/cc-mingw32-gcc-4.2.3-dw2-suffix-build-i686 install && rm -rf *
make DESTDIR=/home/user/cc-mingw32-gcc-4.3-build-i686 install && rm -rf *

make DESTDIR=/home/user/cc-mingw32-gcc-4.4.1-build-i686 install && rm -rf *

(binutils)
make DESTDIR=/home/user/cc-mingw32-binutils-build-i686 install && rm -rf *
make DESTDIR=/home/user/cc-mingw32-binutils-2.19.1-build-i686 install && rm -rf *


**** notes

3 types of compile

build
this is *always* the platform on which you are running the build
process; since we are building on Linux, this is unequivocally going to
specify `linux', with the canonical form being `i686-pc-linux-gnu'.

host
this is a tricky one: it specifies the platform on which whatever we
are building is going to be run; for the cross-compiler itself, that's
also `i686-pc-linux-gnu', but when we get to the stage of building the
runtime support libraries to go with that cross-compiler, they must
contain code which will run on the `i686-pc-mingw32' host, so the `host'
specification should change to this, for the `runtime' and `w32api'
stages of the build.

target
this is probably the one which causes the most confusion; it is only
relevant when building a cross-compiler, and it specifies where the code
which is built by that cross-compiler itself will ultimately run; it
should not need to be specified at all, for the `runtime' or `w32api',
since these are already targetted to `i686-pc-mingw32' by a correct
`host' specification.

??? --enable-fully-dynamic-string, which fixes a bug when passing empty std::string objects between DLLs and EXEs.
??? --disable-libstdcxx-pch, allow compile without a PCH file or stdc++.h file
??? --program-suffix=-4.1, appends -4.1 to exe's
??? --disable-bootstrap
??? --disable-libssp, stack smashing protection
??? --enable-libstdcxx-debug
??? --enable-sjlj-exceptions, debugger mode?
??? --disable-werror, stop on first warning
??? --enable-clocale=gnu --without-included-gettext --with-system-zlib --disable-gmp --disable-mpfr

--enable-version-specific-runtime-libs

Keeps the version specific runtime libraries in a compiler specific
directory rather than placing them right in ${libdir}. You can read
more about this in the gcc documentation (install/CONFIGURE).

cc979
3rd August 2009, 16:26
a cross-compiled vanilla gcc 4.4.1, un-tested

md5: 7A4BCF575DD8D5EE5C7E1FD0306131DE
http://www.speedyshare.com/281844861.html

LoRd_MuldeR
3rd August 2009, 18:55
Thanks. Trying to build x264 with your GCC, but...

LoRd_MuldeR@MULDER_NEU /x264/x264-src
$ ./configure
No working C compiler found.

I already renamed the "xxx-4.4.exe" files to "xxx.exe", but it won't help.

LoRd_MuldeR@MULDER_NEU /x264/x264-src
$ gcc --version
gcc.exe (GCC) 4.4.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Any hints?

cc979
3rd August 2009, 20:35
trying using CC=gcc-4.4 before the configure

i can compile one without the suffix, if needed

_xxl
3rd August 2009, 20:41
Can you please compile lastest stable release from GCC?Without the suffix?

LoRd_MuldeR
3rd August 2009, 20:50
trying using CC=gcc-4.4 before the configure

Okay. I will try like that next time. In the meantime I got GCC 4.4.1 working with Komisar's build.

Can you please compile lastest stable release from GCC?Without the suffix?

Maybe you can use Komisar's GCC 4.4.1 build. In contrast to cc979's build that one worked "out of the box" for me:
http://forum.doom9.org/showpost.php?p=1311229&postcount=2118

TheRyuu
9th August 2009, 01:13
I'd just like to point out that make's '-j' command is useful :) (apparently I'm the only person who doesn't know about this).

make -j3 CFLAGS=etc.... (for dual core)
make -j4 or -j5 for quads

Stuff goes a lot faster, especially if you're building stuff as big as gcc :D
It allows building in parallel.

Edit: followed those steps and successfully build gcc 4.4.1 which works with mingw

TheRyuu
9th August 2009, 05:42
cc-mingw32-gcc-4.4.1-build-i686.7z (http://sempai-net.com/ss-trainee/Dragon/cc-mingw32-gcc-4.4.1-build-i686.7z)

GCC 4.4.1 built with (guess what) GCC 4.4.1, cross compiled from linux. Should work "out of the box" (i.e. no suffix).

Tested it on ffmpeg, seemed to build it fine. Other then that, untested. ;)

$ gcc -v
Using built-in specs.
Target: i686-pc-mingw32
Configured with: ../configure --prefix=/mingw --with-local prefix=/mingw --host=
i686-pc-mingw32 --build=x86_64-pc-linux-gnu --target=i686-pc-mingw32 --disable-s
hared --enable-libgomp --enable-languages=c,c++ --disable-nls --disable-werror -
-disable-win32-registry --enable-sjlj-exceptions --enable-threads=win32 --disabl
e-libstdcxx-pch --enable-fully-dynamic-string --enable-version-specific-runtime-
libs
Thread model: win32
gcc version 4.4.1 (GCC)

_xxl
9th August 2009, 20:41
Maybe you can use Komisar's GCC 4.4.1 build. In contrast to cc979's build that one worked "out of the box" for me.

As.exe from generic build crashes. Tested with WinXP Sp3 and AmdXP.

komisar
18th August 2009, 12:11
_xxl, what options you use for as.exe?

LoRd_MuldeR
24th August 2009, 19:47
TDM's GCC/MinGW is now available in version 4.4.1:
http://www.tdragon.net/recentgcc/

clsid
24th August 2009, 21:01
A custom MinGW32 installer is available here:
http://sourceforge.net/projects/ffdshow-tryout/files/Tools/mingw32_20090823.exe/download

It contains MinGW32, MSYS, GCC 4.4.1, pthreads, YASM, binutils, SDL, etc.

_xxl
21st September 2009, 16:59
@komisar
I get this error when compiling latest ffdshow-tryouts libs.
http://i35.tinypic.com/2q37p8y.jpg
MinGW GCC version:
http://i38.tinypic.com/5oh5kn.jpg
Tested with XP SP3 AMD XP 2000+.

LoRd_MuldeR
18th October 2009, 19:07
GCC 4.4.2 has been released (October 15th). Anybody has compiled/tried MinGW/GCC 4.4.2 yet?

_xxl
18th October 2009, 20:16
http://www.tdragon.net/recentgcc/
The 4.4.1-tdm-2 release is now available. If you were using the first 4.4.1 release, you are urged to upgrade to this new version in order to avoid a bug that caused drastically increased CPU usage in programs compiled with the first version.

komisar
19th October 2009, 18:25
Please test new cross-compile toolchain with GCC 4.4.2 (http://komisar.gin.by/mingw/index.html)

LoRd_MuldeR
19th October 2009, 20:28
Please test new cross-compile toolchain with GCC 4.4.2 (http://komisar.gin.by/mingw/index.html)

Thanks. Will do :)

[EDIT]

Done ;)

http://forum.doom9.org/showpost.php?p=1336163&postcount=1347

Kurtnoise
20th October 2009, 08:45
Please test new cross-compile toolchain with GCC 4.4.2 (http://komisar.gin.by/mingw/index.html)
looks like you forgot to include zlib lib/header for the x86_64-pc-mingw32...

komisar
20th October 2009, 09:05
looks like you forgot to include zlib lib/header for the x86_64-pc-mingw32...
heh, yes, sorry...

Updated.

LoRd_MuldeR
20th October 2009, 19:42
Okay, I encoded the same lossless source with x264 compiled by TDM's GCC 4.4.1-2 and with x264 compiled by Komisar's GCC 4.4.2. Using x264 r1301.

The two H.264 streams came out MD5-identical. So I guess this a good sign ;)

aerodown
21st October 2009, 17:54
hi,

i try komisar cross-mingw.gcc442.generic.20091019 but it give me error when compiling gpac:

gcc -O3 -fno-strict-aliasing -Wno-pointer-sign -DGPAC_HAVE_CONFIG_H -I/home/Eddie/gpac -I/home/Eddie/gpac/include -c -o media_tools/gpac_ogg.o media_tools/gpac_ogg.c
media_tools/gpac_ogg.c: In function 'ogg_stream_flush':
media_tools/gpac_ogg.c:763: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
make[1]: *** [media_tools/gpac_ogg.o] Error 1
make[1]: Leaving directory `/home/Eddie/gpac/src'
make: *** [lib] Error 2

im using winxp sp3 with AMD Phenom.

komisar
21st October 2009, 18:03
aerodown, huh :-\ gpac from svn?

aerodown
21st October 2009, 18:05
aerodown, huh :-\ gpac from svn?

yes.

and by the way i try another with cross-mingw.gcc442.core2.20091019 i can compile with no error, guess i cant use generic one?

komisar
21st October 2009, 18:19
aerodown, i am build with gcc442.generic on i7... no error.

Earlier i tryed to build toolchain for amdfam10, but gcc crash with "Segmentation fault"... I have not found solutions to this problem :( Perhaps this is related to this platform...

_xxl
21st October 2009, 20:31
media_tools/gpac_ogg.c:763: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
make[1]: *** [media_tools/gpac_ogg.o] Error 1
make[1]: Leaving directory `/home/Eddie/gpac/src'
I get this error with some older versions of mingw gcc.

komisar
27th October 2009, 08:59
@komisar
I get this error when compiling latest ffdshow-tryouts libs.
Tested with XP SP3 AMD XP 2000+.
In earler generic-build binutils incorrect compiled... Sorry. In this binutils used SSE2 instructions...

TheRyuu
30th October 2009, 01:34
I've successfully built a working 4.4.2 compiler with cloog/ppl for mingw32 cross compiled from linux if anyone cares.

cc-mingw32-gcc-4.4.2-build-i686-v2.7z (http://www.filefront.com/14823899/cc-mingw32-gcc-4.4.2-build-i686-v2.7z)

Edit:
If anyone is trying to build it with cloog/ppl you have to make sure your cross compiler is built with --disable-shared (to only get static shit) so when you build cloog and the final gcc you add the configure flag --with-host-libstdcxx=-lstdc++ so it actually recognizes that static link (cloog and the final gcc will not build without it). This probably only applies to cross compiled gcc's from linux.

roozhou
30th October 2009, 09:09
media_tools/gpac_ogg.c:763: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
make[1]: *** [media_tools/gpac_ogg.o] Error 1
make[1]: Leaving directory `/home/Eddie/gpac/src'
make: *** [lib] Error 2

im using winxp sp3 with AMD Phenom.

Are you using "make -j4"? This frequently happens to me when using multithread make. Try "make".