C语言 编译器 gcc:错误;无此文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44014748/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 10:39:38  来源:igfitidea点击:

Compiler gcc:error; no such file or directory

cgcc

提问by sarakota

I am extremely new to programming and I am having problems with the basic starting program of, 'hello, world'.

我对编程非常陌生,我在使用“你好,世界”的基本启动程序时遇到了问题。

I have downloaded MinGW and I believe I set it up correctly with the command promt by entering: setx PATH "%PATH%;C:\MinGW\bin"

我已经下载了 MinGW,我相信我通过输入以下命令使用命令提示符正确设置了它: setx PATH "%PATH%;C:\MinGW\bin"

Then I created this code following a guide while using Notepad++

然后我在使用 Notepad++ 时按照指南创建了此代码

#include <stdio.h>

int main(void)
{
  puts("Hello, world!");
  return 0;
}

saving it under c:/code/c/hello.c

将其保存在 c:/code/c/hello.c

When I try to compile it or run it under: gcc -o hello hello.c, I get this error

当我尝试编译它或在以下情况下运行它时:gcc -o hello hello.c,我收到此错误

gcc: error: hello.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.

And I am not sure how to fix this. I have tried looking around, but I cant find any answers or I just don't understand them.

我不知道如何解决这个问题。我试过环顾四周,但我找不到任何答案,或者我只是不理解它们。

回答by Ari0nhh

gcc: error: hello.c: No such file or directory gcc: fatal error: no input files compilation terminated.

gcc:错误:hello.c:没有这样的文件或目录 gcc:致命错误:没有输入文件编译终止。

Means that gccis unable to find your hello.csource file. You should either cd to the source folder:

意味着gcc无法找到您的hello.c源文件。您应该 cd 到源文件夹:

c:
cd c:\code\c\
gcc -o hello.exe hello.c

Or use a full path to the source in the command line:

或者在命令行中使用源的完整路径:

gcc -o c:\code\c\hello.exe c:\code\c\hello.c