I've been reading the GNU make manual and trying to understand how make will search subdirs for files that are dependencies. So far, I've not had much luck.
I have a file hello.cpp which calls a function hello2() in source file hello2/hello2.cpp. BTW, the code does compile and run as long as I have hello.cpp and hello2.cpp in the same dir but that's not the point of the exercise. I have a LARGE project with several subdirs and dozens of files. I thought that by setting VPATH, it would find the source files in the sub dirs. I'm using the Cygnus tools on a WinNT machine. Here is my Makefile:
##########################################
# Makefile
# this one does NOT work
VPATH = .;hello2
objects = hello.o hello2.o
all : hello
hello : $(objects)
gcc -o hello $(objects)
hello.o : hello.cpp
gcc -c hello.cpp
hello2.o : hello2.cpp
##########################################
Here is the error I get:
gcc -c hello2.cpp
gcc: hello2.cpp: No such file or directory
gcc: No input files
make: *** [hello2.o] Error 1
Here's another attempt that did not work:
##########################################
# Makefile
VPATH = \makeTest;\makeTest\hello2
objects = hello.o hello2.o
all : hello
hello : $(objects)
gcc -o hello $(objects)
hello.o : hello.cpp
gcc -c hello.cpp
hello2.o : hello2.cpp
gcc -c hello2.cpp
##########################################
Here's the error:
E:\makeTest>make
gcc -c hello.cpp
make: *** No rule to make target `hello2.cpp', needed by `hello2.o'. Stop.
If I use the full path, as in the makefile below, it compiles but again, not what I'm looking for.
##########################################
# Makefile
# this one does work
# doesn't matter if I have this commented or uncommented VPATH = .;hello2
objects = hello.o hello2.o
all : hello
hello : $(objects)
gcc -o hello $(objects)
hello.o : hello.cpp
gcc -c hello.cpp
hello2.o : hello2/hello2.cpp
gcc -c hello2/hello2.cpp
##########################################
Any help would be appreciated.
- - - - - - - Appended by Scientific-Atlanta, Inc. - - - - - - -
This e-mail and any attachments may contain information which is confidential, proprietary, privileged or otherwise protected by law. The information is solely intended for the named addressee (or a person responsible for delivering it to the addressee). If you are not the intended recipient of this message, you are not authorized to read, print, retain, copy or disseminate this message or any part of it. If you have received this e-mail in error, please notify the sender immediately by return e-mail and delete it from your computer.
