windows 交叉编译 binutils-gdb 时出错

Error cross-compiling binutils-gdb for windows

我在 linux 机器 (Ubuntu) 上从这里 (master b运行ch) 克隆了 binutils-gdb 存储库,我想为 [=34] 编译它=](使用 x86_64_w64_mingw32 工具链)。

首先,我运行./configure用下面的选项来指定交叉编译工具链。

./configure --prefix=/usr/x86_64-w64-mingw32 --target=arm-none-eabi --host=x86_64-w64-mingw32

然后我 运行 make 并得到以下错误(我省略了大部分输出,因为它非常大):

[...]
x86_64-w64-mingw32-gcc  -DHAVE_CONFIG_H  -DWITH_DEFAULT_ALIGNMENT=STRICT_ALIGNMENT     -DDEFAULT_INLINE=0   -Wall -Wdeclaration-after-statement -Wpointer-arith -Wpointer-sign -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wmissing-prototypes -Wdeclaration-after-statement -Wempty-body -Wmissing-parameter-type -Wold-style-declaration -Wold-style-definition -Wno-format -Werror  -DMODET -I. -I. -I../common -I./../common -I../../include -I./../../include -I../../bfd -I./../../bfd -I../../opcodes -I./../../opcodes -I../../intl -g -O2     -c -o callback.o -MT callback.o -MMD -MP -MF .deps/callback.Tpo ./../common/callback.c
./../common/callback.c: In function ‘os_time’:
./../common/callback.c:417:25: error: passing argument 1 of ‘time’ from incompatible pointer type [-Werror=incompatible-pointer-types]
  417 |   return wrap (p, time (t));
      |                         ^
      |                         |
      |                         long int *
In file included from ./../common/callback.c:35:
/usr/share/mingw-w64/include/time.h:230:47: note: expected ‘time_t *’ {aka ‘long long int *’} but argument is of type ‘long int *’
  230 | static __inline time_t __CRTDECL time(time_t *_Time) { return _time64(_Time); }
      |                                       ~~~~~~~~^~~~~
cc1: all warnings being treated as errors
make[3]: *** [Makefile:513: callback.o] Error 1
make[3]: Leaving directory '/media/D/Work/FC/binutils-gdb/sim/arm'
make[2]: *** [Makefile:928: all-recursive] Error 1
make[2]: Leaving directory '/media/D/Work/FC/binutils-gdb/sim'
make[1]: *** [Makefile:8376: all-sim] Error 2
make[1]: Leaving directory '/media/D/Work/FC/binutils-gdb'
make: *** [Makefile:915: all] Error 2

我认为这与 time_t 在主机平台 (Windows) 中被类型定义为 long long int(64 位整数)有关,但是,函数os_time 来自文件 sim/common/callback.c:414(相对于项目根目录的路径),接受一个 long(32 位整数)作为参数:

static long
os_time (host_callback *p, long *t)
{
  return wrap (p, time (t));
}

我该如何解决这个错误?或者 binutils-gdb 是否有任何问题跟踪器?

这是因为您正在构建当前的非发布开发版本 - 我在克隆存储库时从最新的 git 版本构建时遇到了完全相同的错误,0a703a4cedffa6f3824e87f115e8d392e32de191.

如果你真的想从开发树构建,你将不得不等待问题被修复,或者自己修复它——这个答案没有解决。

但如果构建最新发布的版本 2.36.1 就足够了,则此后的过程将起作用(在 Ubuntu 20.04 TLS 上测试):

wget https://ftp.gnu.org/gnu/binutils/binutils-2.36.1.tar.gz
tar zxf binutils-2.36.1.tar.gz
mkdir binutils
cd binutils
../binutils-2.36.1/configure --prefix=$(pwd)/binutils-2.36.1-x86_64-w64-mingw32 --target=arm-none-eabi --program-prefix=arm-none-eabi- --host=x86_64-w64-mingw32
make
make install
ll -gG binutils-2.36.1-x86_64-w64-mingw32/bin/
total 159144
drwxrwxr-x 2     4096 Apr  7 14:41 ./
drwxrwxr-x 6     4096 Apr  7 14:41 ../
-rwxr-xr-x 1  9212998 Apr  7 14:41 arm-none-eabi-addr2line.exe*
-rwxr-xr-x 2  9748961 Apr  7 14:41 arm-none-eabi-ar.exe*
-rwxr-xr-x 2 14457348 Apr  7 14:41 arm-none-eabi-as.exe*
-rwxr-xr-x 1  9077841 Apr  7 14:41 arm-none-eabi-c++filt.exe*
-rwxr-xr-x 1   816086 Apr  7 14:41 arm-none-eabi-elfedit.exe*
-rwxr-xr-x 1 10783524 Apr  7 14:41 arm-none-eabi-gprof.exe*
-rwxr-xr-x 4 14526998 Apr  7 14:41 arm-none-eabi-ld.bfd.exe*
-rwxr-xr-x 4 14526998 Apr  7 14:41 arm-none-eabi-ld.exe*
-rwxr-xr-x 2  9259673 Apr  7 14:41 arm-none-eabi-nm.exe*
-rwxr-xr-x 2 10655762 Apr  7 14:41 arm-none-eabi-objcopy.exe*
-rwxr-xr-x 2 14908446 Apr  7 14:41 arm-none-eabi-objdump.exe*
-rwxr-xr-x 2  9748961 Apr  7 14:41 arm-none-eabi-ranlib.exe*
-rwxr-xr-x 2  6156460 Apr  7 14:41 arm-none-eabi-readelf.exe*
-rwxr-xr-x 1  9193640 Apr  7 14:41 arm-none-eabi-size.exe*
-rwxr-xr-x 1  9190290 Apr  7 14:41 arm-none-eabi-strings.exe*
-rwxr-xr-x 2 10655762 Apr  7 14:41 arm-none-eabi-strip.exe*

签出 binutils-2_36_1 标签后,我没有测试从 git 存储库构建:

git -C binutils-gdb checkout binutils-2_36_1

但它应该可以工作,如果标记的是打包在存档文件中的内容,应该是这种情况。