mingw64 and gcc 4.7.0 cross compile

2012-05-14
2013-06-06
  • Kenney Phillis
    Kenney Phillis
    2012-05-14

    I'm having issues with building a complete cross compile tool-chain for mingw64 under Linux. I am going for a gcc 4.7.0 build with openmp support, and graphite optimization support.

    To begin with, I am using a system (Gentoo/Sabayon based ) with gcc 4.6.3 and binutils v2.22 as a base. I already know I have most of the requirements meet for creating cross compilers. The only issue I could possibly see is that I have mingw32 installed at /usr/bin/mingw32-gcc ( and accompanying files/program).

    As for the libraries I am attempting to use, I have already downloaded the following libraries:
    libgmp 5.05, libmpfr 3.1.0, mpc 0.9, Binutils v2.22, gcc 4.7.0, CLooG-PPL v0.15.11, PPL v0.12.1 and mingw64 v2.0.3.

    As for what I will require when the installation is complete (in languages): C, C++, Objective C, Objective C++, GO, and Java. I do not require Fortran or Ada, but being able to use this would be nice. As for special Features within gcc I definitely want to make sure I have OpenMP support, and the graphite loop optimizations ( requires Parma Polyhedra Library (PPL) version 0.11, or  CLooG-PPL version 0.15 )

    As for the compiling, I am mostly following the build instructions outlined at:
    mingw-w64-v2.0.3/mingw-w64-doc/howto-build/mingw-w64-howto-build.txt

    The only changes I have made where to use separate folders for each build stage, and follow some of the tweaks given for building/installing gcc 4.7.0 using linux from scratch's documentation.

    kphillis@localhost ~$ ls ~/win64/tars
    binutils-2.22.tar.bz2  cloog-ppl-0.15.11.tar.gz  gcc-4.7.0.tar.bz2  gmp-5.0.5.tar.bz2  mingw-w64-v2.0.3.tar.gz  mpc-0.9.tar.gz  mpfr-3.1.0.tar.bz2  ppl-0.12.1.tar.bz2

    For binutils, I used the Following Configuration:
    ./configure -target=x86_64-w64-mingw32 \
    -enable-targets=x86_64-w64-mingw32,i686-w64-mingw32 \
    -with-sysroot=/opt/mingw64 –prefix=/opt/mingw64

    (There where no noticable errors at this point)

    The Second stage was the headers, but I found that this had issues with the proper method to handle non-root compiles where sudo is used during the make install step only.

    (from the mingw64-headers folder)
    ./configure -build=`gcc -dump-machine` -host=x86_64-w64-mingw32 \
    -with-sysroot=/opt/mingw64 –prefix=/opt/mingw64
    make
    sudo env PATH=$PATH:/opt/mingw64/bin make instal

    Currently, Other than the sudo issue, there is no major bug with compile at this point. However the issues start to appear when I go about building gcc, and the accompanying tools.  For this, I make a few changes, and follow the linux from scratch instructions a little bit… That said, I performed the following steps to build the stage 1 gcc compiler:

    tar -xjvf tars/gcc-4.7.0.tar.bz2
    cd gcc-4.7.0
    tar -xjf  ../tars/gmp-5.0.5.tar.bz2
    tar -xjf ../tars/mpfr-3.1.0.tar.bz2
    tar -zxf ../tars/mpc-0.9.tar.gz
    mv -v mpfr-3.1.0 mpfr
    mv -v gmp-5.0.5 gmp
    mv -v mpc-0.9 mpc
    mkdir gcc-build-stage1
    cd gcc-build-stage1
    ../gcc-4.7.0/configure -with-sysroot=/opt/mingw64 -prefix=/opt/mingw64 -with-newlib -without-headers -target=x86_64-w64-mingw32 -enable-targets=all -with-mpfr-include=../gcc-4.7.0/mpfr/src -with-mpfr-lib=../gcc-4.7.0/mpfr/src/.libs -enable-static -disable-shared
    make -j8
    sudo make install

    At the end of these steps there is libstdc++ error, but this is not enough to prevent the compiler from installing.

    With this set, I go ahead and build/install the CRT according to instructions. This works, but the sudo issue is still a major issue. ( the install stage should not require the compiler to be ran if you have already called make ).

    Now I go ahead and move on to a stage 2 setup, and this is done with the following commands:
    mkdir gcc-build-stage2
    cd gcc-build-stage2
    ../gcc-4.7.0/configure -with-sysroot=/opt/mingw64 -prefix=/opt/mingw64 -with-newlib -without-headers -target=x86_64-w64-mingw32 -enable-targets=all -with-mpfr-include=../gcc-4.7.0/mpfr/src -with-mpfr-lib=../gcc-4.7.0/mpfr/src/.libs
    make -j8
    sudo make install

    At this point, I would have expected everything to compile and install, but instead I wind up with the following error:

    libtool: compile:  /home/kphillis/win64/gcc-build-stage2/./gcc/xgcc -shared-libgcc -B/home/kphillis/win64/gcc-build-stage2/./gcc -nostdinc++ -L/home/kphillis/win64/gcc-build-stage2/x86_64-w64-mingw32/libstdc++-v3/src -L/home/kphillis/win64/gcc-build-stage2/x86_64-w64-mingw32/libstdc++-v3/src/.libs -L/opt/mingw64/x86_64-w64-mingw32/lib -L/opt/mingw64/mingw/lib -isystem /opt/mingw64/x86_64-w64-mingw32/include -isystem /opt/mingw64/mingw/include -B/opt/mingw64/x86_64-w64-mingw32/bin/ -B/opt/mingw64/x86_64-w64-mingw32/lib/ -isystem /opt/mingw64/x86_64-w64-mingw32/include -isystem /opt/mingw64/x86_64-w64-mingw32/sys-include -I/home/kphillis/win64/gcc-4.7.0/libstdc++-v3/../libgcc -I/home/kphillis/win64/gcc-build-stage2/x86_64-w64-mingw32/libstdc++-v3/include/x86_64-w64-mingw32 -I/home/kphillis/win64/gcc-build-stage2/x86_64-w64-mingw32/libstdc++-v3/include -I/home/kphillis/win64/gcc-4.7.0/libstdc++-v3/libsupc++ -Wall -Wextra -Wwrite-strings -Wcast-qual -Wabi -fdiagnostics-show-location=once -ffunction-sections -fdata-sections -frandom-seed=eh_alloc.lo -g -O2 -c ../../../../gcc-4.7.0/libstdc++-v3/libsupc++/eh_alloc.cc -o eh_alloc.o
    In file included from /home/kphillis/win64/gcc-build-stage2/x86_64-w64-mingw32/libstdc++-v3/include/x86_64-w64-mingw32/bits/gthr.h:150:0,
                     from /home/kphillis/win64/gcc-build-stage2/x86_64-w64-mingw32/libstdc++-v3/include/ext/concurrence.h:36,
                     from ../../../../gcc-4.7.0/libstdc++-v3/libsupc++/eh_alloc.cc:37:
    /home/kphillis/win64/gcc-build-stage2/x86_64-w64-mingw32/libstdc++-v3/include/x86_64-w64-mingw32/bits/gthr-default.h: In function ‘int __gthread_setspecific(__gthread_key_t, const void*)’:
    /home/kphillis/win64/gcc-build-stage2/x86_64-w64-mingw32/libstdc++-v3/include/x86_64-w64-mingw32/bits/gthr-default.h:621:27: error: types may not be defined in casts
    /home/kphillis/win64/gcc-build-stage2/x86_64-w64-mingw32/libstdc++-v3/include/x86_64-w64-mingw32/bits/gthr-default.h:621:27: error: no matching function for call to ‘__gthread_setspecific(__gthread_key_t, const void*)::<anonymous union>::._272(const void*&)’
    /home/kphillis/win64/gcc-build-stage2/x86_64-w64-mingw32/libstdc++-v3/include/x86_64-w64-mingw32/bits/gthr-default.h:621:27: note: candidates are:
    /home/kphillis/win64/gcc-build-stage2/x86_64-w64-mingw32/libstdc++-v3/include/x86_64-w64-mingw32/bits/gthr-default.h:621:27: note: __gthread_setspecific(__gthread_key_t, const void*)::<anonymous union>::._272()
    /home/kphillis/win64/gcc-build-stage2/x86_64-w64-mingw32/libstdc++-v3/include/x86_64-w64-mingw32/bits/gthr-default.h:621:27: note:   candidate expects 0 arguments, 1 provided
    /home/kphillis/win64/gcc-build-stage2/x86_64-w64-mingw32/libstdc++-v3/include/x86_64-w64-mingw32/bits/gthr-default.h:621:27: note: __gthread_setspecific(__gthread_key_t, const void*)::<anonymous union>::._272(const __gthread_setspecific(__gthread_key_t, const void*)::<anonymous union>&)
    /home/kphillis/win64/gcc-build-stage2/x86_64-w64-mingw32/libstdc++-v3/include/x86_64-w64-mingw32/bits/gthr-default.h:621:27: note:   no known conversion for argument 1 from ‘const void*’ to ‘const __gthread_setspecific(__gthread_key_t, const void*)::<anonymous union>&’
    make: ***  Error 1
    make: Leaving directory `/home/kphillis/win64/gcc-build-stage2/x86_64-w64-mingw32/libstdc++-v3/libsupc++'
    make: ***  Error 1
    make: Leaving directory `/home/kphillis/win64/gcc-build-stage2/x86_64-w64-mingw32/libstdc++-v3'
    make: ***  Error 2
    make: Leaving directory `/home/kphillis/win64/gcc-build-stage2/x86_64-w64-mingw32/libstdc++-v3'
    make: ***  Error 2
    make: Leaving directory `/home/kphillis/win64/gcc-build-stage2'
    make: ***  Error 2