【发布时间】:2021-12-30 11:10:44
【问题描述】:
这是我在 VS 代码终端上运行代码时的样子。
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS D:\C C++> cd "d:\C C++\" ; if ($?) { g++ TEST.C -o TEST } ; if ($?) { .\TEST }
D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): in function `main':
C:/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
PS D:\C C++>
这是我尝试运行的简单程序。
#include<stdio.h>
int main(){
int age;
printf("Enter age\n");
scanf("%d",&age);
printf("age is %d",age);
return 0;
}
【问题讨论】:
-
我从未见过有人尝试运行这样的代码。简单的 gcc myCode.c -o myCode.exe 不起作用?
-
在运行程序之前保存文件,应该可以解决错误。
-
这能回答你的问题吗? undefined reference to `WinMain@16'
-
是的,我只需要保存它。我忘记自动保存已关闭,谢谢您的帮助!
标签: c visual-studio-code terminal