10

I want to cross-compile GCC. I am using MSYS2 as a shell, and mingw-w64 as the compiler.

I have downloaded binutils-2.25 and I configure with:

../binutils/./configure --target=sh3eb-elf --prefix=C:/tempinstall/ --disable-nls

I get an error when I try to build binutils on libiberty/pex-unix file:

In function 'pex_wait': error: 'F_GETFD' undeclared (first use in this function) error: 'FD_CLOEXEC' undeclared (first use in this function) error: 'F_SETFD' undeclared (first use in this function) error: 'F_DUPFD' undeclared (first use in this function)

In function 'restore_fd': error: 'FD_CLOEXEC' undeclared (first use in this function) error: 'F_SETFD' undeclared (first use in this function)

In function 'pex_unix_fdopenw': error: 'F_SETFD' undeclared (first use in this function) error: 'FD_CLOEXEC' undeclared (first use in this function)

I have built the same compiler few months ago without problems. But I have since changed OS(Windows 7 to W10) and compiler(MinGW-GCC 4.8 to Mingw64-GCC 4.9)

I followed this tutorial

Community
  • 1
  • 1
Intelligide
  • 279
  • 2
  • 14
  • I find a strange line on libiberty/config.log `pexecute = "pex-unix"`. Maybe configure don't detect Windows 10. Do you think it's possible? – Intelligide Aug 27 '15 at 13:50

2 Answers2

9

I found the solution:

I use MSys2 with msys2_shell that defines --msys as host system.

But when I use mingw32_shell( that defines --mingw32 as host), GNU-Make compile pex-win32 and it's works fine

divy3993
  • 5,732
  • 2
  • 28
  • 41
Intelligide
  • 279
  • 2
  • 14
1

The problem is that, by default, when running GNU configure scripts under MSYS2, the build and host system is reported as i686-pc-msys, or x86_64-pc-msys .

However , the configure script for binutils (and gcc) does not recognize msys in the third part , so the build defaults to a Unix build. This , in turn, leads to pex-unix being compiled, which requres the POSIX features in sys/wait.h, which is not provided by MinGW-w64.

The configure scripts do have special cases for targets mingw* and cygwin*, which lead to compiling pex-win32.c instead, avoiding the problem.


I think the intended solution is that when we want to build using MinGW-w64, we should launch MSYS2 using the shortcut "MSYS2 MinGW 32-bit" or "MSYS2 MinGW 64-bit". These shortcuts set up environment variables so that the Host string is set to i686-w64-mingw32 or i686-w64-mingw64 (or x86_64 instead of i686 in both cases if you used 64-bit MSYS2). Then the binutils configure script picks up its mingw case and build the right thing.

However, compiling binutils-2.28, even though it did try to build pex-win32.c, I got a bunch of compile errors: _open was not declared, and so on.

I did not investigate this further because I tried something else first which turned out to work: I launched the standard MSYS2 shell (not the MinGW-w64 variants), I put /mingw32/bin on the front of PATH, and I passed the argument --build=i686-w64-mingw32 to configure for binutils and gcc.

This succeeded and I was able to build a complete cross toolchain (for arm-eabi v0 actually), which did not have MSYS2 dependency.

M.M
  • 138,810
  • 21
  • 208
  • 365
  • 1
    I'm not sure how you didn't get any upvotes for this response as this worked for me. The only difference is that I had to uninstall gcc from MSYS2 using `pacman -R gcc`, install MingW32 from [GitHub releases](https://github.com/niXman/mingw-builds-binaries/releases) and unzip it into the root drive, open the MingW64 terminal, set `PATH=${PATH}:/c/mingw32/bin`, run `configure` and then `make`. – Joe Feb 25 '23 at 23:01
  • I assume is this way because of the nature of the MSYS2 GCC compiler being POSIX compliant – Joe Feb 25 '23 at 23:30
  • 1
    @joe thanks for the comment. Low-traffic question I guess -- not many people doing this! – M.M Feb 26 '23 at 03:03