开发者

Problems with directories making a simple makefile

开发者 https://www.devze.com 2023-02-09 01:39 出处:网络
I want to make a simple makefile for a C project that have the following directories. -Project - src - a.c

I want to make a simple makefile for a C project that have the following directories.

 -Project  
   - src 
     - a.c  
     - b.c
     - main.c  
   - headers  
     - a.h  
     - b.h   
   - build  
     - makefile  
     - project.exe 

And here it's the makefile that I've done.

project: a.o b.o main.o
    cc -o sesion0 a.o b.o main.o
a.o: ../src/a.c ../headers/a.h 
b.o: ../src/b.c ../headers/b.h 
main.o: ../src/main.c ../headers/a.h ../headers/b.h 

But when I execute the make order, it tell's me that the file or directory a.o, b.o and main.o doesn't exist and also that there's not input files. In the end shows this error:

make: *** [project] Error 1

Does anyone know why this happen or where I have the error? I d开发者_如何学运维on't know very well how to manage the directories in the makefile.

Thanks.


Make has built-in rules for making x.o from x.c, but not from ../src/x.c. In other words, paths of input and output must be the same, only the file extension differs.

You can fix it by using VPATH for directory search:

VPATH = ../src:../headers
a.o: a.c a.h 
b.o: b.c b.h 
main.o: main.c a.h b.h 
0

精彩评论

暂无评论...
验证码 换一张
取 消