Makefile неправильно использует неявные правила.Я следую этому руководству здесь .
Вот мой make-файл:
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.
Вот мой файл main.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>