【发布时间】:2018-09-13 00:31:58
【问题描述】:
Makefile 未正确使用隐式规则。我正在关注本指南here。
这是我的生成文件:
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>
【问题讨论】:
-
您使用的是哪个版本的 Make? (如果不确定,请尝试
make -v。) -
这是 GNU Make 4.1。现在试用 Autotools,它似乎更容易使用。
标签: makefile