【发布时间】:2012-02-14 03:05:57
【问题描述】:
函数.h
#include<stdio.h>
void print_hello(void);
int factorial(int n);
main.c
#include<stdio.h>
#include<functions.h>
int main()
{
print_hello();
printf("\nThe factorial is: %d \n",factorial(5));
return 0;
}
你好.c
#include<stdio.h>
#include<functions.h>
void print_hello()
{
printf("\nHello World!\n");
}
factorial.c
#include<stdio.h>
#include<functions.h>
int factorial(int n)
{
if(n!=1)
{
return(n*factorial(n-1));
}
else
return 1;
}
制作文件
exec : \
compile
echo "Executing the object file"
./compile
compile : main.o hello.o factorial.o
echo "Compiling"
gcc -o compile $^
main.o : main.c functions.h
gcc -c main.c -I./INCLUDE -I./SRC
hello.o : hello.c functions.h
gcc -c hello.c -I./INCLUDE -I./SRC
factorial.o : factorial.c functions.h
gcc -c factorial.c -I./INCLUDE -I./SRC
文件夹:make_example\INCLUDE\functions.h 文件夹: make_example\SRC\main.c 文件夹:make_example\SRC\hello.c 文件夹: make_example\SRC\factorial.c 文件夹:make_example\makefile
将 make 文件编译为“desktop:~/make_example$ make”时出现错误
make: * 没有规则来制作目标main.c', needed bymain.o'。停下来。”
请帮我理解这个错误的原因
【问题讨论】: