admin';?>

首页 / 个人作品

compile gcc 4.9.4 + latest-Mingw-w64 on linux 2019.05

By admin  •  2020-03-28 10:54:38  •  327次点击
永久外链: https://i.otherhill.com/static/771b0514709f11eab405809b202ce664.html

Compile gcc4.9.4 +  Latest-Mingw-w64 under Linux, build Cross-compile-toolchain  , to generate software which can run on  windows xp and xp+  x32/x64.

We generate all static compile.


Reference:https://pete.akeo.ie/2010/07/compiling-mingw-w64-with-multilib-on.html

Reference: /run/media/lixing/6T_20181101_3/mingw32_20190521_src/mingw-w64-mingw-w64_master/mingw-w64-doc/howto-build/mingw-w64-howto-build.txt

finally directory layout:

/works/tools/compiler/mingw32/
bin
    x86_64-w64-mingw32-c++, x86_64-w64-mingw32-gcc,....
lib
   gcc
libexec
   gcc
share
x86_64-w64-mingw32
    bin
    include
    lib
    lib32
mingw(ln  -s     x86_64-w64-mingw32 mingw ,it's x86_64-w64-mingw32's soft-link)
        
1.At first, build Binutils-2.29

cd /run/media/lixing/6T_20181101_3/mingw32_20190521_src/binutils-2.29
mkdir build
cd build
../configure --prefix=/works/tools/compiler/mingw32 --with-sysroot=/works/tools/compiler/mingw32 --enable-gold --enable-ld --enable-lto --target=x86_64-w64-mingw32 --enable-targets=x86_64-w64-mingw32,i686-w64-mingw32
make
make install 

2.Compile mingw-w64-headers of  mingw-w64-mingw-w64_master
cd /run/media/lixing/6T_20181101_3/mingw32_20190521_src/mingw-w64-mingw-w64_master/mingw-w64-headers
mkdir build
cd build
 ../configure --host=x86_64-w64-mingw32 --prefix=/works/tools/compiler/mingw32/x86_64-w64-mingw32
make
make install 

3.create soft-link

cd /works/tools/compiler/mingw32
ln -s x86_64-w64-mingw32 mingw

4.Compile gcc4.9.4, Gcc, pass 1
gmp-6.1.0.tar.gz
mpc-1.0.2.tar.gz
mpfr-3.1.4.tar.gz
unzip them to path gcc4.9.4 ,corresponding to decompressed folder name is:gmp,mpc,mpfr,so that gcc will found them when gcc compiling.
cd /run/media/lixing/6T_20181101_3/mingw32_20190521_src/gcc4.9.4

we need build gcc outside src directory.
cd ..
mkdir gcc_build
cd gcc_build

Reference:  /run/media/lixing/6T_20181101_3/mingw32_20190521_src/gcc4.9.4/INSTALL/configure.html


../gcc4.9.4/configure --with-sysroot=/works/tools/compiler/mingw32 --prefix=/works/tools/compiler/mingw32  --enable-languages=c,c++ --enable-multiarch --enable-multilib --with-multilib-list=m32,m64  --disable-nls --target=x86_64-w64-mingw32  --with-system-zlib   --enable-version-specific-runtime-libs  --enable-fully-dynamic-string  --enable-libgomp --with-host-libstdcxx="-lstdc++ -lsupc++"  --enable-threads=win32 --with-gnu-ld --with-gnu-as --enable-lto --enable-shared --with-dwarf --enable-64bit --enable-libssp

make all-gcc -j4
make install-gcc

5.mingw-w64-crt

cd /run/media/lixing/6T_20181101_3/mingw32_20190521_src/mingw-w64-mingw-w64_master
export PATH=/works/tools/compiler/mingw32/bin:$PATH
mkdir build
cd build

mypath=/works/tools/compiler/mingw32/x86_64-w64-mingw32

../configure --with-sysroot=$mypath --prefix=$mypath --host=x86_64-w64-mingw32 --enable-multilib --enable-lib32 --enable-lib64 --enable-experimental --enable-targets=x86_64-w64-mingw32,i686-w64-mingw32

make -j4
make install

6.Build libgcc
cd /run/media/lixing/6T_20181101_3/mingw32_20190521_src/gcc_build
"make all-target-libgcc", then "make install-target-libgcc".

7.pthreads
https://sourceware.org/pthreads-win32/
export PATH=/works/tools/compiler/mingw32/bin:$PATH

MINGW32_PATH=/works/tools/compiler/mingw32
make clean GC-static CROSS=x86_64-w64-mingw32- CFLAGS='-I. -I$(MINGW32_PATH)/x86_64-w64-mingw32/include --sysroot=$(MINGW32_PATH)/x86_64-w64-mingw32'  -f GNUmakefile PTW32_FLAGS="-DPTW32_STATIC_LIB"
After sucess,Install it:
cp -f pthread.h $(MINGW32_PATH)/x86_64-w64-mingw32/include
cp -f sched.h $(MINGW32_PATH)/x86_64-w64-mingw32/include
cp -f semaphore.h $(MINGW32_PATH)/x86_64-w64-mingw32/include
cp -f config.h $(MINGW32_PATH)/x86_64-w64-mingw32/include/pthread_config.h
cp -f libpthread.a $(MINGW32_PATH)/x86_64-w64-mingw32/lib
GNUmakefile中,ARTI='-m32' stand for build x32,so you'll must build it again for x32,then:
cp -f libthread.a $(MINGW32_PATH)/x86_64-w64-mingw32/lib32

modify $(MINGW32_PATH)/x86_64-w64-mingw32/include/pthread.h:
#if defined(HAVE_PTW32_CONFIG_H)
#include "config.h"
#endif /* HAVE_PTW32_CONFIG_H */
change to:
//#if defined(HAVE_PTW32_CONFIG_H)
#include "pthread_config.h"
//#endif /* HAVE_PTW32_CONFIG_H */

Download:http://oltag.com:8080/yaolixing/18/06/26/01/GNUmakefile.txt

above link may be invalid, so I introduce it:
/run/media/lixing/6T_20181101_3/mingw32_20190521_src/pthreads/GNUmakefile:
DEVROOT    = /works/tools/compiler/mingw32/x86_64-w64-mingw32

DLLDEST    = $(DEVROOT)/dll
LIBDEST    = $(DEVROOT)/lib
ARTI=-m32

CC      = $(CROSS)gcc $(ARTI)
CXX     = $(CROSS)g++ $(ARTI)

ifeq ('$(ARTI)','-m32')
ARFLAGS = --target=pe-i386
DLLTOOL = $(CROSS)dlltool -m i386
RC    = $(CROSS)windres -F pe-i386
else
ARFLAGS = --target=pe-x86-64
DLLTOOL = $(CROSS)dlltool
RC    = $(CROSS)windres
endif

AR    = $(CROSS)ar $(ARFLAGS)
RANLIB  = $(CROSS)ranlib $(ARFLAGS)  

OPT    = $(CLEANUP) -O3 # -finline-functions -findirect-inlining
XOPT    =
RCFLAGS        = --include-dir=. -I/works/tools/compiler/mingw32/include

CFLAGS    = $(OPT) $(XOPT) -I. -I/works/tools/compiler/mingw32/include --sysroot=/works/tools/compiler/mingw32 -DHAVE_PTW32_CONFIG_H -Wall

8.Build libgcc last!
cd /run/media/lixing/6T_20181101_3/mingw32_20190521_src/gcc_build
make -j4 && make install

Now, you can generate x32 exe for windows:
/works/tools/compiler/mingw32/bin/x86_64-w64-mingw32-gcc  -m32  helloworld.cxx -o main.exe

But, How can I use them on configure?

export PATH=/works/tools/compiler/mingw32/bin:$Path

./confiugre --host=i686-w64-mingw32  for x32

./configure --host=x86_64-w64-mingw32 for x64.

 

and you must create i686-w64-mingw32-xx for your  build,them is only  .sh file:

i686-w64-mingw32-gcc:

#!/bin/sh
currpath=$(cd "$(dirname "$0")"; pwd)
${currpath}/x86_64-w64-mingw32-gcc -m32 -march=i686  -mthreads  $@ 

i686-w64-mingw32-g++:

#!/bin/sh
currpath=$(cd "$(dirname "$0")"; pwd)
"${currpath}/x86_64-w64-mingw32-g++" -m32 -march=i686 -mthreads $@

i686-w64-mingw32-g++:

#!/bin/sh
currpath=$(cd "$(dirname "$0")"; pwd)
"${currpath}/x86_64-w64-mingw32-g++" -m32 -march=i686  -mthreads $@

i686-w64-mingw32-ld:

#!/bin/sh
currpath=$(cd "$(dirname "$0")"; pwd)
${currpath}/x86_64-w64-mingw32-ld -m pe-i386 $@ 

i686-w64-mingw32-windres:

#!/bin/sh
currpath=$(cd "$(dirname "$0")"; pwd)
${currpath}/x86_64-w64-mingw32-windres -D_WIN32=1 --target=pe-i386 $@

 

ln -s x86_64-w64-mingw32-...    i686-w64-mingw32-...


0 回复 | 直到2022-09-30 23:07添加回复

回复

最近更新

私信给我
生成图片 生成二维码 生成密码
清空