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

在musl-libc系统(Gentoo)下用TCC编译gmake遇重定义错误求助

在Gentoo musl-libc系统用TCC编译gmake的wchar_t重定义错误解决

问题重现

在Gentoo musl-libc环境下,用TCC编译gmake:

  1. 执行配置:CC=tcc ./configure --program-prefix=g
  2. 运行./build.sh后报错:

config.status: creating ./lib/alloca.h__
config.status: creating ./lib/fnmatch.h__
config.status: creating ./lib/glob.h__
compiling lib/concat-filename.c...
do tcc -DHAVE_CONFIG_H -I./lib -Ilib -I./lib -I./src -Isrc -I./src -g -c -o ./lib/libgnu_a-concat-filename.o ./lib/concat-filename.c
In file included from ./lib/concat-filename.c:22:
In file included from ./lib/concat-filename.h:20:
In file included from /usr/include/stdlib.h:21:
/usr/include/bits/alltypes.h:15: error: incompatible redefinition of 'wchar_t'
Compilation failed.

(注:日志中do ...行是手动添加的编译命令打印)

问题根源确实是TCC自带的/usr/lib/tcc/include头文件和musl系统头文件对wchar_t的定义冲突。

解决方法

1. 优先使用musl系统头文件编译

TCC默认会先搜索自己的头文件目录,导致和musl的定义冲突。可以在编译时强制指定系统头文件优先级:

  • 重新配置时指定CFLAGS参数:
CC=tcc CFLAGS="-I/usr/include -B/usr/lib/musl/lib/" ./configure --program-prefix=g

然后再运行./build.sh。

  • 或者直接修改build.sh里的编译命令,把-I/usr/include放在所有-I参数最前面,确保系统头文件先被搜索。

2. 绝对不要直接移除#include stdlib.h

stdlib.h是标准库核心头文件,包含大量必要的类型和函数声明,删掉它会引发更多编译错误,完全不可取。

3. 修改TCC自带头文件(可选,谨慎操作)

如果上面的方法无效,可以编辑/usr/lib/tcc/include/wchar.h(或相关定义wchar_t的头文件),注释掉其中对wchar_t的定义,让TCC使用musl的版本。但这种修改可能影响TCC编译其他程序,属于临时 workaround,不推荐长期使用。

内容的提问来源于stack exchange,提问作者Andrew K

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 18:05:00