Makefile:Error1

csg*_*pie 9 c makefile

我有一个非常简单的c程序:

int main()
{
  return(1);
}
Run Code Online (Sandbox Code Playgroud)

和一个简单的Makefile:

all:
    gcc -ansi -pedantic -o tmp tmp.c
    ./tmp
Run Code Online (Sandbox Code Playgroud)

但是,当我键入时,make我收到以下错误消息:

$ make
gcc -ansi -pedantic -o tmp tmp.c
./tmp
make: *** [all] Error 1
Run Code Online (Sandbox Code Playgroud)

我错过了什么明显的事情?

Ala*_*nse 24

如果执行的任何命令退出并出现错误,则退出并显示错误.

由于您的程序以代码1退出,因此make将其视为错误,然后返回相同的错误.

您可以通过在行的开头放置 - 来告诉make忽略错误,如下所示:

-./tmp
Run Code Online (Sandbox Code Playgroud)

您可以在此处查看有关makefile中错误处理的更多信息.


Oli*_*rth 5

您正在从应用程序返回错误代码1。将其报告为错误是Make的工作!


cod*_*ict 5

这是因为您的程序返回1。

使用gcc进行编译,该编译很好(返回0),因此可以继续执行,但是您的程序返回的非零值,因此make将其报告为错误。

成功完成的程序应返回0,否则返回非零值。