For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > March 2007 > Q. Using VPATH in make ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Q. Using VPATH in make ?
Lou Pecora

2007-03-25, 7:04 pm

I have a Mac Powerbook (Al, Mac OS X 10.4.8) and I cannot get VPATH to
work in make so I wonder what I am doing wrong. I am trying to compile
a file (general.c) in a directory listed in VPATH, but I get an error
that the file cannot be found. loulibs.mak is my makefile in a
different directory from general.c. Here it is:

VPATH=/Users/louispecora/Code/general/

general.o: loulibs.mak general.c general.h
g++ -g -c -D_X_ -D$(RANGE) -D$(DEBUG) -o general.o general.c


--- I get the following error when I do make -f loulibs.mak

louispec% make -f loulibs.mak
g++ -g -c -D_X_ -D_RANGE_ -D_DEBUG_ -o general.o general.c
powerpc-apple-darwin8-g++-4.0.1: general.c: No such file or directory
powerpc-apple-darwin8-g++-4.0.1: no input files
make: *** [general.o] Error 1
Exit 2

--- Does anyone know what I am doing wrong?

Thanks for any help.

-- Lou Pecora (my views are my own) REMOVE THIS to email me.
Måns Rullgård

2007-03-25, 7:04 pm

Lou Pecora <pecora@anvil.nrl.navy.mil> writes:

> I have a Mac Powerbook (Al, Mac OS X 10.4.8) and I cannot get VPATH to
> work in make so I wonder what I am doing wrong. I am trying to compile
> a file (general.c) in a directory listed in VPATH, but I get an error
> that the file cannot be found. loulibs.mak is my makefile in a
> different directory from general.c. Here it is:
>
> VPATH=/Users/louispecora/Code/general/
>
> general.o: loulibs.mak general.c general.h
> g++ -g -c -D_X_ -D$(RANGE) -D$(DEBUG) -o general.o general.c


Something like this should work:

general.o: general.c general.h loulibs.mak
g++ -g -c -D_X_ -D$(RANGE) -D$(DEBUG) -o $@ $<

I wonder, though, why you are compiling a C source file with g++. If
the file is really C++, it should be named *.cc, *.C, *.cpp or *.cxx.
If you follow the usual naming conventions, you can take advantage of
builtin implicit rules in make. Read the manual for your version of
make to find out exactly what they are.

--
Måns Rullgård
mans@mansr.com
Lou Pecora

2007-03-25, 7:04 pm

In article <yw1x3b3typan.fsf@thrashbarg.mansr.com>,
Måns Rullgård <mans@mansr.com> wrote:

>
> Something like this should work:
>
> general.o: general.c general.h loulibs.mak
> g++ -g -c -D_X_ -D$(RANGE) -D$(DEBUG) -o $@ $<
>
> I wonder, though, why you are compiling a C source file with g++. If
> the file is really C++, it should be named *.cc, *.C, *.cpp or *.cxx.
> If you follow the usual naming conventions, you can take advantage of
> builtin implicit rules in make. Read the manual for your version of
> make to find out exactly what they are.


Thanks. I will have to learn what -o $@ $< means and how to use that
symbolism. Yes, general.c is actually a C++ source file. I have a lot
of 'legacy' files from when I converted to C++. I should change names,
you're right.

-- Lou Pecora (my views are my own) REMOVE THIS to email me.
Måns Rullgård

2007-03-25, 7:04 pm

Lou Pecora <pecora@anvil.nrl.navy.mil> writes:

> In article <yw1x3b3typan.fsf@thrashbarg.mansr.com>,
> Måns Rullgård <mans@mansr.com> wrote:
>
>
> Thanks. I will have to learn what -o $@ $< means and how to use that
> symbolism. Yes, general.c is actually a C++ source file. I have a lot
> of 'legacy' files from when I converted to C++. I should change names,
> you're right.


$@ expands to the current target, in this case general.o. $< expands
to the first dependency. The make manual lists a number of other
useful variables.

--
Måns Rullgård
mans@mansr.com
Lou Pecora

2007-03-26, 7:05 pm

In article <yw1xtzw9x74b.fsf@thrashbarg.mansr.com>,
Måns Rullgård <mans@mansr.com> wrote:

> Lou Pecora <pecora@anvil.nrl.navy.mil> writes:
>
>
> $@ expands to the current target, in this case general.o. $< expands
> to the first dependency. The make manual lists a number of other
> useful variables.


Thanks. I managed to google those symbols and did find some explanation
in the gnu area -- although a bit cryptic. Your explanation above helps.

-- Lou Pecora (my views are my own) REMOVE THIS to email me.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com