交叉编译 – autotools:C编译器无法创建可执行文件

我在OS X上构建了一个x86_64-elf内核.我的构建系统是autotools.我在OS X上成功编译了
gcc以交叉编译x86_64-elf.当我运行从autotools生成的configure脚本时,我遇到了一个问题:

configure: error: C compiler cannot create executables
See `config.log' for more details

所以我看一下config.log并看到:

cannot find crt0.o: No such file or directory
collect2: error: ld returned 1 exit status

这很有道理.交叉编译器不会生成可执行文件,因为没有关联的运行时.但我不需要或希望我的编译器生成可执行文件,我将为我的引导程序适当地链接它.我怎么告诉autotools不检查这个?

最佳答案 运行configure脚本时,请确保指定以下gcc标志(将它们添加到CFLAGS环境变量):

-nostdlib -nostartfiles -nodefaultlibs -ffreestanding

如果您不知道如何将这些附加到CFLAGS的末尾,请尝试以下方法:

export CFLAGS=$CFLAGS -nostdlib -nostartfiles -nodefaultlibs -ffreestanding
点赞