问题描述
在Windows上安装了VS代码和MinGW。为C / C ++添加了IntelliSense扩展。我已经从bin中添加了gcc.exe的路径。键入一个简单的C程序。显示错误。请帮忙! 错误是:
PS F:\C\Chapter 1> gcc 001_first.c
C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.1.0/../../../../i686-w64-mingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x39): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
问题还在于:
#include errors detected. Please update your include path. Squiggles are disabled for this translation unit( Path is mentioned )
Cannot open source file "stdio.h"
解决方法
IntelliSense错误仅表示VS Code无法找到头文件。您需要设置您的包含路径。您可以了解它(以及其他许多知识)here。
第二个更有趣。我也遇到过几次。答案是:将-mconsole
附加到gcc命令。这是因为默认情况下,它会尝试构建需要WinMain
的桌面应用程序。