[SOLVED] Re: setting CPU_TYPE when cross-compiling from Linux to Windows

Claude Heiland-Allen claude at mathr.co.uk
Fri Jan 3 11:22:59 UTC 2020


Hi,

On 29/12/2019 19:25, Niels Möller wrote:
> Claude Heiland-Allen <claude at mathr.co.uk> writes:
>
>> However trying the method suggested in the documentation also fails,
>> but in a different way:
>>
>> ```
>> CC_FOR_BUILD="gcc" \
>> CPP_FOR_BUILD="gcc -E" \
>> CFLAGS="-march=native -O3 -fomit-frame-pointer" \
>> CXXFLAGS="-march=native -O3 -fomit-frame-pointer" \
>> LDFLAGS="-static-libgcc -static-libstdc++" \
>> CPPFLAGS="-D__USE_MINGW_ANSI_STDIO" \
>> ./configure --build=zen-pc-linux-gnu --host=zen-w64-mingw32 \
>>    --prefix=/home/claude/winNATIVE
>> ...
>> config.status: linking mpn/x86_64/zen/gmp-mparam.h to gmp-mparam.h
>> config.status: executing libtool commands
>> configure: summary of build options:
>>
>>    Version:           GNU MP 6.1.99
>>    Host type:         zen-w64-mingw32
>>    ABI:               64
>>    Install prefix:    /home/claude/winNATIVE
>>    Compiler:          gcc
>>    Static libraries:  yes
>>    Shared libraries:  no
>>
>> configure: If wine64 is installed, use make check TESTS_ENVIRONMENT=wine64.
>> ```
>>
>> Notice it uses compiler `gcc` instead of `x86_64-w64-mingw32-gcc`,
>> which leads to a build for Linux, not Windows.
> Autoconf has a convenience feature to automatically pick a
> cross-compiler based on the host triplet. But that works only if
> cross-compiler name and host-triplet match perfectly. Otherwise, you
> must specify the correct cross compiler explicitly, with
> CC=x86_64-w64-mingw32-gcc.

Aha, thanks for this tip, I found an incantation that works:

```
CC=x86_64-w64-mingw32-gcc \
CC_FOR_BUILD=x86_64-linux-gnu-gcc \
CPPFLAGS=-D__USE_MINGW_ANSI_STDIO \
LDFLAGS="-static-libgcc -static-libstdc++" \
./configure \
   --build=x86_64-linux-gnu \
   --host=x86_64-w64-mingw32 \
   --enable-fat \
   --enable-static \
   --disable-shared \
   --prefix=/home/claude/wintmp/
```

The `CPPFLAGS` is necessary to avoid test failure in printf/scanf. I 
found that `make check` works (I have binfmt support enabled so wine is 
invoked automatically), but `make check TESTS_ENVIRONMENT=wine64` as 
suggested fails:

```
make[5]: Entering directory '/home/claude/wintmp/src/gmp/tests'
wine: Bad EXE format for Z:\bin\bash..
```
>> Trying a fat build (thanks for the pointer to this method, I think
>> it's what I really need) also fails, at `make check`:
> Can't say why this fails. If you have tried different configs in the
> same build tree, try starting over from make distclean.
This tip may also have helped, thanks again,


Claude
-- 
https://mathr.co.uk



More information about the gmp-bugs mailing list