添加独立选项后,为什么printf函数仍然可用

时间:2019-01-02 03:17:00

标签: gcc compilation freestanding

通常,我已经阅读了以下文章,检查了gcc语言标准中的“独立式/托管”定义,但尚未解决我的疑问。

https://gcc.gnu.org/onlinedocs/gcc/Standards.html

https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html

Freestanding GCC and builtin functions

我在Win7中使用托管的gcc / cygwin。我发现生成的.out,.map或.exe文件对于具有-ffreestanding和不具有-ffreestanding的不同版本都是相同的。

C文件(test.c):

#include <stdio.h>

int main(int ac, char **av)
{
    printf("test1");
    return 0;
}

下面列出了两种不同版本的命令行:

gcc test.c -o test1.exe -std=gnu99 -O2 -Wall -Wextra -Wl,-Map,test1.map

gcc test.c -o test2.exe -std=gnu99 -ffreestanding -O2 -Wall -Wextra -Wl,-Map,test2.map

test1.exe和test2.exe都可以通过构建并在运行时显示“ test1”。但是我曾以为-ffreestanding可能会由于“找不到stdio标头”,“不包括标准库”或“找不到printf实现”而导致编译失败。

即使使用-ffreestanding选项,托管的gcc似乎也不能用作独立的gcc。

有人可以帮助澄清吗?添加独立选项后,为什么printf函数仍然可用?

0 个答案:

没有答案