Including source directories in make file commands

Jun 30, 2009 at 6:44pm
Hi,

I wrote a makefile (shown below) for a single-file C++ program in linux. I can successfully run the makefile if the source file and makefile are in the same directory. Trouble begins once my source file is moved to a different directory.
------------------------------------------
SRCS := bm.cpp
#VPATH = ./Top
INCLUDE_DIRECTORIES_MAIN = ./Top
CFLAGS =
GCC = g++
ALL_CFLAGS = $(addprefix -I,$(INCLUDE_DIRECTORIES_MAIN)) $(CFLAGS)

bm.o:
$(GCC) $(ALL_CFLAGS) -c bm.cpp -o $@
-------------------------------------------

I tried using VPATH and also -Idir g++ option. I still get the following error:
-----------------------------
g++ -I./Top -c bm.cpp -o bm.o
g++: bm.cpp: No such file or directory
g++: no input files
make: *** [bm.o] Error 1
-----------------------------

Any suggestions are appreciated. I do not understand why the -I option is not working.
Jun 30, 2009 at 7:49pm
-I (dash-eye) is used only to specify the paths by which the compiler searches for header files. I think you are using it to try to tell the compiler what directories to search for the .cpp files you are trying to compile.
Jun 30, 2009 at 11:56pm
Thanks for pointing out jsmith. That was very helpful. I have another question.
I have many .cpp files in various folders. Is there a way to give a list of directories that make-rules can search from? Do you know whether VPATH can be used to do this?
Jul 1, 2009 at 11:43am
Mmm, I'm sorry, but I am completely inept when it comes to creating Makefiles. I have to defer to someone else.
Jul 1, 2009 at 7:51pm
Thanks for the help. I figured out that VPATH can be set to the list of directories containing source files. This would enable writing a cleaner makefile since you can list the sourcefile names without the complete path for each file, while indicating to the makefile the directories where it should look for source files.

Here is a helpful reference for those interested in usage of VPATH
http://www.cmcrossroads.com/content/view/11088/268/
Last edited on Jul 1, 2009 at 11:21pm
Topic archived. No new replies allowed.