Nik*_*kos 5 c windows linker gcc mingw
我有一个简单的“Hello World!” 我的桌面上有一个名为 hello.c 的 c 程序:
#include <stdio.h>
int main() {
printf("Hello world!\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我运行以下命令。
到目前为止一切都很好。但是,我无法链接它。除其他命令外,我还尝试过以下命令:
ld -o hello.exe hello.o
ld -o hello.exe hello.o -lgcc
ld -o hello.exe hello.o -nostdlib -lgcc
Run Code Online (Sandbox Code Playgroud)
什么都不起作用。我在每种情况下遇到的链接错误是:
hello.o:hello.c:(.text+0x9): undefined reference to `__main'
hello.o:hello.c:(.text+0x15): undefined reference to `puts'
Run Code Online (Sandbox Code Playgroud)
我如何链接这个汇编程序hello.o以便最终生成可执行程序hello.exe?我缺少什么?[使用 Windows 8.1,Mingw 版本 0.6.2。] 提前致谢。
即使您对澄清问题的回答不是特别有用:
尝试类似的东西
Run Code Online (Sandbox Code Playgroud)ld hello.o -lmsvcrt -entry=_main -subsystem=console -o hello.exe
如果您想查看标准 gcc 使用的链接器命令行,请像这样调用 gcc:
Run Code Online (Sandbox Code Playgroud)gcc test.c -o test -Wl,-v
最后几行输出是您应该使用的...