VS Code终端make命令报错:未识别及安装后cc执行失败
解决C语言编译时
make相关的两个错误 问题重现
作为编程新手,按照C语言教程执行以下命令:
code hello.c make hello ./hello
先后遇到两个错误:
- 初始错误:
make命令未识别
make : The term 'make' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 make hello + CategoryInfo : ObjectNotFound: (make:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
- 安装
make后新错误:cc编译器找不到
cc hello.c -o hello process_begin: CreateProcess(NULL, cc hello.c -o hello, ...) failed. make (e=2): The system cannot find the file specified. make: *** [<builtin>: hello] Error 2
解决方案
针对第二个错误(cc找不到)
cc是GCC编译器的别名,Windows系统默认没有安装C编译器,按以下步骤解决:
步骤1:安装C编译器
推荐两种选择:- MinGW-W64:下载对应版本(建议选x86_64-posix-seh架构),安装后找到安装目录下的
bin文件夹(比如C:\mingw64\bin) - Visual Studio:安装时勾选「C++开发工具集」,安装完成后使用「x64 Native Tools Command Prompt for VS」终端执行命令(该终端会自动配置编译器环境)
- MinGW-W64:下载对应版本(建议选x86_64-posix-seh架构),安装后找到安装目录下的
步骤2:配置环境变量(仅针对MinGW)
右键「此电脑」→「属性」→「高级系统设置」→「环境变量」,在系统变量的Path中添加MinGW的bin文件夹路径。添加完成后重启终端,输入gcc --version,能显示版本信息即配置成功。步骤3:重新编译运行
回到代码所在目录,再次执行make hello,编译成功后用./hello运行程序。
新手替代方案(跳过make)
如果觉得make配置麻烦,新手可以直接用编译器命令编译,效果和make hello一致:
gcc hello.c -o hello ./hello
内容的提问来源于stack exchange,提问作者Klaus
相关产品推荐
相关产品推荐

