在 Visual Studio Code 中编译 C 程序时出错 [英] Error while compiling C program in Visual Studio Code
问题描述
我在 Visual Studio Code 的编辑器中用 C 语言编写了一个基本程序,但在尝试编译它时出现以下错误.
#includeint main(){printf("你好世界");返回0;}
我收到以下错误消息:
<块引用>[Running] cd "c:\Users\Chaitanya\Documents\initial\" &&gcc pro1.c -opro1&&"c:\Users\Chaitanya\Documents\initial\"pro1c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe:c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../libmingw32.a(main.o):(.text.startup+0xb0):对WinMain@16" collect2.exe 的未定义引用:错误:ld 返回 1退出状态[完成] 在 0.198 秒内以代码 = 1 退出
控制台应用程序和Win32应用程序之间存在差异.您选择了后者,但对前者进行了编程.
控制台应用程序有一个名为 main
的主函数.
Win32 应用程序有一个名为 WinMain
的主函数;链接器错过了它,所以它会退出.
实际上,Win32 应用程序也有一个名为 main
的主函数.但它是由它所链接的库提供的,它在准备一些 Win32 东西后调用 WinMain
.
I have written a basic program in C language in the editor of Visual Studio Code but I am getting the following error while trying to compile it.
#include<stdio.h>
int main()
{
printf("Hello World");
return 0;
}
I am getting the following error message:
[Running] cd "c:\Users\Chaitanya\Documents\initial\" && gcc pro1.c -o pro1 && "c:\Users\Chaitanya\Documents\initial\"pro1 c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../libmingw32.a(main.o):(.text.startup+0xb0): undefined reference to `WinMain@16' collect2.exe: error: ld returned 1 exit status [Done] exited with code=1 in 0.198 seconds
There is a difference between console application and Win32 application. You chose the latter but programmed the former.
A console application has a main function called main
.
A Win32 application has a main function called WinMain
; the linker misses it so it bails out.
Actually a Win32 application has a main function called main
, too. But it is provided by the library it is linked with, and it calls WinMain
after preparing some Win32 stuff.
这篇关于在 Visual Studio Code 中编译 C 程序时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!