C语言 生成文件:错误 1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4034392/
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
Makefile: Error1
提问by csgillespie
I have a very simple c programme:
我有一个非常简单的c程序:
int main()
{
return(1);
}
and a simple Makefile:
和一个简单的 Makefile:
all:
gcc -ansi -pedantic -o tmp tmp.c
./tmp
However, when I type makeI get the following error message:
但是,当我输入时,make我收到以下错误消息:
$ make
gcc -ansi -pedantic -o tmp tmp.c
./tmp
make: *** [all] Error 1
What obvious thing am I missing?
我错过了什么明显的东西?
回答by Alan Geleynse
Make exits with an error if any command it executes exits with an error.
如果它执行的任何命令以错误退出,则以错误退出。
Since your program is exiting with a code of 1, make sees that as an error, and then returns the same error itself.
由于您的程序以代码 1 退出,make 将其视为错误,然后本身返回相同的错误。
You can tell make to ignore errors by placing a - at the beginning of the line like this:
您可以通过在行的开头放置一个 - 来告诉 make 忽略错误,如下所示:
-./tmp
You can see more about error handling in makefiles here.
您可以在此处查看有关 makefile 中错误处理的更多信息。
回答by Oliver Charlesworth
You're returning an error code of 1 from your application. It's Make's job to report this as an error!
您从应用程序返回错误代码 1。将其报告为错误是 Make 的工作!
回答by codaddict
This is because your program is returning 1.
这是因为您的程序返回 1。
Makes does the compilation using gcc, which goes fine (returns 0) so it proceeds with the execution, but your program return a non-zero value, so make reports this as an error.
Makes 使用 gcc 进行编译,它运行良好(返回0),因此它继续执行,但您的程序返回一个非零值,因此 make 将此报告为错误。
A program on successful completion should return 0and return a non-zero value otherwise.
成功完成的程序应该返回0,否则返回一个非零值。

