Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Source files are in a directory called ‘src’.
Include files are in a directory called ‘include’
These two directories are under a directory called ‘work’

There are 1 or 2 source files and 2-3 include files..How can we implement this???
I know how to implement this in a single directory,but any one let me help when include files and source files are in different directories...
Posted
Comments
renj00790 24-Jan-12 22:53pm    
CC=gcc
CDEBUG=-g
OBJ=hello.o hello1.o main.o


my_project : $(OBJ)
$(CC) $(OBJ) -o my_project
main.o : function.h function1.h
$(CC) -c main.c
hello.o : function.h hello.c
$(CC) -c hello.c
hello1.o : function1.h hello1.c
$(CC) -c hello1.c
.PHONY clean:
clean :
rm -rf *.o



My Makefile look like this...can u implement this by using different dir

1 solution

I explicitely create variables for sources and include files, e.g.
SRCDIR = src
INCDIR = include
BINDIR = bin


and the use it to build sources, e.g.

...

$(BINDIR)/foo:    $(SRCDIR)/foo.c $(INCDIR)/foo.h $(INCDIR)/common.h
                  $(CC) $(CPPFLAGS) $(LDFLAGS) -o $@ $<


I believe there are many more concise ways to do the same.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900