makefile失败-隐式规则编译一个对象文件,但不';其余的我不编译

makefile失败-隐式规则编译一个对象文件,但不';其余的我不编译,makefile,Makefile,Makefile未正确使用隐式规则。我遵循这个指南 这是我的makefile: objects = main.o hello.o hello : $(objects) cc -o hello $(objects) hello.o : defs.h main.o : defs.h hello.h .PHONY : clean clean : -rm hello $(objects) 我得到以下错误: cc: error: main.o: No such file or dir

Makefile未正确使用隐式规则。我遵循这个指南

这是我的makefile:

objects = main.o hello.o
hello : $(objects)
    cc -o hello $(objects)

hello.o : defs.h
main.o : defs.h hello.h

.PHONY : clean
clean :
    -rm hello $(objects)
我得到以下错误:

cc: error: main.o: No such file or directory
它创建目标代码hello.o,但不为main.c创建。如果我交换行,main在上面,它将创建main.o,但不会创建hello.o

这是我的主.c文件:

#include "defs.h"
#include "hello.h"

int main(int argc, char** argv) {
   display_hello();
   return (EXIT_SUCCESS);
}
这是我的hello.c文件:

#include "defs.h"

void display_hello()
{
    printf("Hello!\n");
}
我的hello.h文件:

#ifndef HELLO_H
#define HELLO_H

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

#endif /* HELLO_H */

void display_hello();
这是我的defs.h文件:

#ifndef DEFS_H
#define DEFS_H

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

#endif /* DEFS_H */

#include <stdio.h>
#include <stdlib.h>
\ifndef DEFS\H
#定义定义定义
#ifdef_uucplusplus
外部“C”{
#恩迪夫
#ifdef_uucplusplus
}
#恩迪夫
#endif/*DEFS_H*/
#包括
#包括

对我来说很好,我创建了以下文件

可能是@Beta所说的
make
版本,但即使是GNU make的旧版本也可以很好地实现这一点


否则,请确保在makefile中使用制表符缩进,而不是空格。

您使用的Make版本是什么?(如果您不确定,请尝试
make-v
)它是GNU make 4.1。现在尝试使用自动工具,似乎更容易使用。
$ make
cc    -c -o main.o main.c
cc    -c -o hello.o hello.c
cc -o hello main.o hello.o