You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

M68K平台GCC 14.1.0工具链编译失败,求解决方案

问题:Windows MSYS2下构建M68K架构GCC 14.1.0工具链失败

在Windows MSYS2环境下构建面向M68K架构的C/C++ GNU GCC工具链(组件包含GCC-14.1.0、NEWLIB-4.4.0、BINUTILS-2.42、GDB-14.2)时,编译GCC-14.1.0阶段报错失败,提示coshl、cosl、sinhl、sinl函数隐式声明。将GCC版本替换为13.3.0后可正常完成构建,且ARM、AVR平台编译GCC-14.1.0无异常。

编译GCC的脚本片段

#----------------------------------
# 同时构建GCC和NEWLIB
#----------------------------------
mkdir gcc-newlib
(
   cd gcc-newlib
   #--------------
   echo "配置gcc和newlib(详细信息见build/gcc-newlib-configure.log)"
   ../../source/${GCC}/configure \
   --build=${BUILD_MACH} \
   --host=${HOST_MACH} \
   --target=${TARGET} \
   --prefix=${PREFIX} \
   --enable-languages=c,c++ \
   --with-arch=m68k \
   --with-newlib \
   --with-headers=${SRCDIR}/source/gcc-14.1.0/newlib/libc/include \
   --with-gnu-as \
   --with-gnu-ld \
   --with-gmp \
   --with-mpfr \
   --with-mpc \
   --without-long-double-128 \
   --disable-werror \
   --disable-decimal-float \
   --disable-libffi \
   --disable-libgomp \
   --disable-libmudflap \
   --disable-libphobos \
   --disable-libquadmath \
   --disable-libssp \
   --disable-libstdcxx-pch \
   --disable-multilib \
   --disable-nls \
   --disable-shared \
   --disable-threads \
   --disable-tls \
   --with-pkgversion='M68K GNU GCC ToolChain-${RELISE}' \
   > ../gcc-newlib-configure.log 2>&1
   #-------------
   echo "构建gcc和newlib(详细信息见build/gcc-newlib-make.log)"
   make -j $JOBCOUNT > ../gcc-newlib-make.log 2>&1
   #-------------
   echo "安装gcc和newlib(详细信息见build/gcc-newlib-install.log)"
   make install > ../gcc-newlib-install.log 2>&1
   #-------------
   echo "完成"
)

具体错误日志

CC       libm/complex/libm_a-cargf.o
  CC       libm/complex/libm_a-catanhf.o
  CC       libm/complex/libm_a-cexpf.o
  CC       libm/complex/libm_a-cpowf.o
  CC       libm/complex/libm_a-csinhf.o
  CC       libm/complex/libm_a-cabsl.o
  CC       libm/complex/libm_a-creall.o
  CC       libm/complex/libm_a-cimagl.o
  CC       libm/complex/libm_a-ccoshl.o
../../../../source/gcc-14.1.0/newlib/libm/complex/ccoshl.c: 在函数‘ccoshl’中:
../../../../source/gcc-14.1.0/newlib/libm/complex/ccoshl.c:43:13: 错误:函数‘coshl’隐式声明,你是不是想写‘coshf’? [-Wimplicit-function-declaration]
   43 |         w = coshl(x) * cosl(y) + (sinhl(x) * sinl(y)) * I;
      |             ^~~~~
      |             coshf
../../../../source/gcc-14.1.0/newlib/libm/complex/ccoshl.c:43:24: 错误:函数‘cosl’隐式声明,你是不是想写‘cosf’? [-Wimplicit-function-declaration]
   43 |         w = coshl(x) * cosl(y) + (sinhl(x) * sinl(y)) * I;
      |                        ^~~~
      |                        cosf
../../../../source/gcc-14.1.0/newlib/libm/complex/ccoshl.c:43:35: 错误:函数‘sinhl’隐式声明,你是不是想写‘sinhf’? [-Wimplicit-function-declaration]
   43 |         w = coshl(x) * cosl(y) + (sinhl(x) * sinl(y)) * I;
      |                                   ^~~~~
      |                                   sinhf
../../../../source/gcc-14.1.0/newlib/libm/complex/ccoshl.c:43:46: 错误:函数‘sinl’隐式声明,你是不是想写‘sinf’? [-Wimplicit-function-declaration]
   43 |         w = coshl(x) * cosl(y) + (sinhl(x) * sinl(y)) * I;
      |                                              ^~~~
      |                                              sinf
make[3]: *** [Makefile:43137: libm/complex/libm_a-ccoshl.o] 错误 1
make[3]: *** 等待未完成的任务....
  CC       libm/complex/libm_a-cacoshl.o
make[3]: 离开目录 '/home/mario/gcc141_maker/build/gcc-newlib/m68k-elf/newlib'
make[2]: *** [Makefile:5304: all] 错误 2
make[2]: 离开目录 '/home/mario/gcc141_maker/build/gcc-newlib/m68k-elf/newlib'
make[1]: *** [Makefile:13461: all-target-newlib] 错误 2
make[1]: 离开目录 '/home/mario/gcc141_maker/build/gcc-newlib'
make: *** [Makefile:1069: all] 错误 2

解决方法

1. 调整long double相关配置

GCC 14.1.0对M68K架构的long double处理逻辑有变更,当前配置的--without-long-double-128可能不匹配M68K默认的80位long double类型。尝试:

  • 添加--with-long-double-format=ieee明确指定long double格式
  • 或者移除--without-long-double-128参数,让工具链自动适配M68K的long double类型

2. 分阶段单独构建组件

不要同时构建GCC和newlib,改为分步骤构建:

  1. 先编译并安装binutils
  2. 构建仅支持C语言的交叉GCC(不关联newlib)
  3. 用刚构建的交叉编译器单独编译安装newlib
  4. 最后重新构建完整的GCC(包含C++语言支持)

3. 手动修复头文件缺失问题

报错原因是ccoshl.c引用的函数声明未被正确包含,可直接修改源码:

  • 在newlib/libm/complex/ccoshl.c开头添加头文件引用:#include <math.h>
  • 检查newlib/libc/include/math.h,如果缺少long double版本函数的声明,手动添加:
long double coshl(long double x);
long double cosl(long double x);
long double sinhl(long double x);
long double sinl(long double x);

4. 应用官方兼容性补丁

GCC 14.1.0针对M68K与newlib的兼容性问题可能已有修复补丁,可检查GCC或newlib的官方更新记录,下载对应补丁应用到源码后再编译。

内容的提问来源于stack exchange,提问作者Mario Giovinazzo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 13:08:12