在linux 上编译生成windows上运行的exe程序,交叉编译环境的配置( 平台:gentoo linux)

gentoo 给安装交叉编译环境,进行了简化,

首先安装crossdev

emerge crossdev

这个东西安装好后并不能真正编译exe 程序 ,它只是一个帮你安装交叉编译环境的工具

你可以运行这个命令试试

crossdev

Usage: crossdev [options] --target TARGET Options: --b, --binutils ver Specify version of binutils to use --g, --gcc ver Specify version of gcc to use --k, --kernel ver Specify version of kernel headers to use --l, --libc ver Specify version of libc to use -S, --stable Use latest stable versions as default -C, --clean target Uninstall specified target -P, --portage opts Options to pass to emerge (see emerge(1)) --with[out]-headers Build C library headers before C compiler? Stage Options: -s0, --stage0 Build just binutils -s1, --stage1 Also build a C compiler (no libc/C++) -s2, --stage2 Also build kernel headers -s3, --stage3 Also build the C library (no C++) -s4, --stage4 Also build a C++ compiler [default] Extra Fun (must be run after above stages): --ex-only Skip the stage steps above --ex-gcc Build extra gcc targets (gcj/ada/etc...) --ex-gdb Build a cross gdb --ex-insight Build a cross insight Target (-t) takes a tuple ARCH-VENDOR-OS-LIBC; see 'crossdev -t help'

然后再运行 crossdev -t help

会显示出所有支持的平台

Supported Architectures: - alpha - arm / armeb - hppa (parisc) - ia64 - i386 / i486 / i586 / i686 (x86) - m68k - mips / mipsel / mips64 / mips64el - powerpc (ppc) / powerpc64 (ppc64) - sparc / sparc64 - s390 / s390x - sh / sh[1-5] / sh64 - x86_64 (amd64) Supported C Libraries: - glibc (gnu) - klibc [prob wont work] - newlib [bare metal/no operating system] - uclibc [not all arches are ported] Special Targets: - avr http://www.nongnu.org/avr-libc/ - bfin http://blackfin.uclinux.org/ - h8300 http://h8300-hms.sourceforge.net/ - mingw32 http://www.mingw.org/ - msp430 http://mspgcc.sourceforge.net/ - nios2 http://www.altera.com/products/ip/processors/nios2/ni2-index.html - xc16x http://www.infineon.com/ - ee / iop / dvp (ps2) [Playstation 2 targets] - ppu / spu (cell) [Cell/Playstation 3 targets] Softfloat toolchains: Include 'softfloat' in the 'vendor' field e.g. armeb-softfloat-linux-uclibc powerpc-booya_softfloat-linux-gnu

运行 这个命令才真正安装目标平台的交叉编译环境 ,我安装的是i686 ,mingw32(好像是表示win32 ,不太明白,但是安装这个可以编译生成exe)

 crossdev i686-mingw32

这个过程中会下载并安装binutil ,gcc 等软件

* Host Portage ARCH: x86 * Target Portage ARCH: x86 * Target System: i686-mingw32 * Stage: 4 (C/C++ compiler) * binutils: binutils-[latest] * gcc: gcc-[latest] * headers: w32api-[latest] * libc: mingw-runtime-[latest] * PORTDIR_OVERLAY: /resource/pkg/gentoo/layman/gentoo-china * PORT_LOGDIR: /var/log/portage * PKGDIR: /resource/pkg/gentoo/binPackages/cross/i686-mingw32 * PORTAGE_TMPDIR: /var/tmp/cross/i686-mingw32 

 

完成之后,你会发现会有许多以i686-mingw32开头的命令如


i686-mingw32-addr2line i686-mingw32-g++ i686-mingw32-ranlib i686-mingw32-ar i686-mingw32-gcc i686-mingw32-readelf i686-mingw32-as i686-mingw32-gcov i686-mingw32-size i686-mingw32-c++ i686-mingw32-gprof i686-mingw32-strings i686-mingw32-c++filt i686-mingw32-ld i686-mingw32-strip i686-mingw32-cpp i686-mingw32-nm i686-mingw32-windmc i686-mingw32-dlltool i686-mingw32-objcopy i686-mingw32-windres i686-mingw32-dllwrap i686-mingw32-objdump

 

进行测试一下

hello.c

#include<stdio.h> int main(){ printf("hello!"); }

编译 i686-mingw32-gcc  hello.c  -o hello.exe

在目录 下会生成一个hello.exe

拿到windows 下的命令行下测试一下,发现可以运行

 

 

你可能感兴趣的:(在linux 上编译生成windows上运行的exe程序,交叉编译环境的配置( 平台:gentoo linux))