MakeFile

Hello,
Lets say that i want to use makefile in Unix,
i have the following files inside (/home/makefile/) which are:
main.cpp
factorial.cpp
Hello.cpp

and also have another file inside(/home/makefile/inc/) which is:
function.h

...
now i want to use makefile,
what i did is here but it wont work..when all files are in one direction it works good, but when i change the direction of (function.h) it gives me error.
Help me plzzz.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
SRC=/makefile/inc/

all:		prog.exe
		echo "build done"

prog.exe:	main.o hello.o factorial.o
		g++ main.o hello.o factorial.o -o prog.exe 

main.o:		main.cpp $(SRC)functions.h
		g++ -c main.cpp

hello.o:	hello.cpp $(SRC)functions.h
		g++ -c hello.cpp

factorial.o:	factorial.cpp $(SRC)functions.h
		g++ -c factorial.cpp


Last edited on
You have SRC pointing to /makefile/inc; however you said the makefile is in /home/makefile/. It that is indeed the case, you need to set SRC this way:

1
2
3

SRC=/home/makefile/inc/
Thnks,
Yes i did it but still not working
What doesn't work?
It's not enough to tell make where to find the files; the compiler must also know.So you must either:

#include "inc/function.inc"

or

g++ -c x.cpp -I inc

Hope this helps.

[edit] Fixed as per ne555's comment.
Last edited on
g++ -c x.cpp -I .
I think that's default behaviour, maybe you mean g++ -c x.cpp -I inc
Yes. Fixed above.
Topic archived. No new replies allowed.