For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > September 2004 > Help with makefiles









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 Help with makefiles
Max

2004-09-26, 8:56 pm

I've already read about 10 tutorials on makefiles, still have this
problem and hoping someone here could help me out. I'm creating a
project for my C++ class, it'll be tested on a UNIX system with cxx
compiler. Bellow I've pasted my current makefile for it:

------------------------------------------------------------------------

p1 : main.o DataManager.o EventList.o Event.o NameList.o Name.o
cxx -w0 -std strict_ansi main.o DataManager.o EventList.o Event.o
NameList.o Name.o -o p1

main.o : main.cpp DataManager.h Event.h Name.h
cxx -w0 -std srtict_ansi -c main.cpp

DataManager.o : DataManager.cpp DataManager.h Event.h Name.h EventList.h
cxx -w0 -std srtict_ansi -c DataManager.cpp

EventList.o : EventList.cpp EventList.h Event.h
cxx -w0 -std srtict_ansi -c EventList.cpp

Event.o : Event.cpp Event.h NameList.h
cxx -w0 -std srtict_ansi -c Event.cpp

NameList.o : NameList.cpp NameList.h Name.h
cxx -w0 -std srtict_ansi -c NameList.cpp

Name.o : Name.cpp Name.h
cxx -w0 -std srtict_ansi -c Name.cpp

------------------------------------------------------------------------

So the way this works is, Name is no dependant on anything, NameList is
dependant on Name, Event is dependant on NameList, and so on towards the
top.

The problem that I'm having is that when I run make, I get an error
message saying that it doesn't know how to make Name.h. Basically it
takes the last dependency of the second label and gives me that error
message. This seems a little strange since I'm listing Name.h as a
dependency, not trying to make it. Any insight on what I'm doing wrong?
Never used makefiles before, so I'm sure there has to be something...

Btw, as I already got a few ideas on this, let me also say this. It
doesn't seem to have anything to do with the .h files in the
dependencies, nor does it have anything to do with make being unable to
find the files. Unless it's looking in some other place, but I have no
idea why it would be doing that. I'm calling make from the directory
that has the makefile and all of the needed .h and .cpp files. Not
something to do with capitalization either. Already checked all of this.

Thanks for any help.
Jens.Toerring@physik.fu-berlin.de

2004-09-27, 3:57 am

Max <max@mxserve.com> wrote:
> I've already read about 10 tutorials on makefiles, still have this
> problem and hoping someone here could help me out. I'm creating a
> project for my C++ class, it'll be tested on a UNIX system with cxx
> compiler. Bellow I've pasted my current makefile for it:


> ------------------------------------------------------------------------


> p1 : main.o DataManager.o EventList.o Event.o NameList.o Name.o
> cxx -w0 -std strict_ansi main.o DataManager.o EventList.o Event.o
> NameList.o Name.o -o p1


> main.o : main.cpp DataManager.h Event.h Name.h
> cxx -w0 -std srtict_ansi -c main.cpp


> DataManager.o : DataManager.cpp DataManager.h Event.h Name.h EventList.h
> cxx -w0 -std srtict_ansi -c DataManager.cpp


> EventList.o : EventList.cpp EventList.h Event.h
> cxx -w0 -std srtict_ansi -c EventList.cpp


> Event.o : Event.cpp Event.h NameList.h
> cxx -w0 -std srtict_ansi -c Event.cpp


> NameList.o : NameList.cpp NameList.h Name.h
> cxx -w0 -std srtict_ansi -c NameList.cpp


> Name.o : Name.cpp Name.h
> cxx -w0 -std srtict_ansi -c Name.cpp


> ------------------------------------------------------------------------


> So the way this works is, Name is no dependant on anything, NameList is
> dependant on Name, Event is dependant on NameList, and so on towards the
> top.


> The problem that I'm having is that when I run make, I get an error
> message saying that it doesn't know how to make Name.h. Basically it
> takes the last dependency of the second label and gives me that error
> message. This seems a little strange since I'm listing Name.h as a
> dependency, not trying to make it. Any insight on what I'm doing wrong?


That would mean that there's no file named Name.h in the current directory
- and since you tell make you need it to build main.o it tries to figure
out how to create it but finds no method to do that. If Name.h exists make
should not have any reason to try to create it.

> Btw, as I already got a few ideas on this, let me also say this. It
> doesn't seem to have anything to do with the .h files in the
> dependencies, nor does it have anything to do with make being unable to
> find the files. Unless it's looking in some other place, but I have no
> idea why it would be doing that. I'm calling make from the directory
> that has the makefile and all of the needed .h and .cpp files. Not
> something to do with capitalization either. Already checked all of this.


All I can imagine is that you may have managed to e.g. append a space
to the file name or embed some non-printable character into the name.
Since you probably #include Name.h in some way into main.cpp a quick
check would be to simply run the command manually - if there's some-
thing wrong with the file name also the #include would fail.

Regards, Jens

PS. 'srtict_ansi' looks fishy, I guess you want 'strict_ansi';-)
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Max

2004-09-27, 3:57 am

Jens.Toerring@physik.fu-berlin.de wrote:
> All I can imagine is that you may have managed to e.g. append a space
> to the file name or embed some non-printable character into the name.
> Since you probably #include Name.h in some way into main.cpp a quick
> check would be to simply run the command manually - if there's some-
> thing wrong with the file name also the #include would fail.
>
> Regards, Jens
>
> PS. 'srtict_ansi' looks fishy, I guess you want 'strict_ansi';-)


Heh oh yes, strict_ansi has been changed since, forgot to change it in
what I was pasting. As for the file name, I can’t find a thing wrong
with it. In fact, someone also suggested that I should just remove the
..h files from the dependency lists. When I do that it starts complaining
about the .cpp files. Just now I've also tried using complete paths
instead of relative ones... Same story. This thing is driving me crazy.

All of the cxx lines run just fine. I manually went ahead and executed
every cxx line in that file starting from the bottom and working my way
up. Everything works just as it should. But when put into this make file
I just don't know where it's looking for the dependencies that it
doesn't find them.
Max

2004-09-27, 3:57 am

Max wrote:

> Jens.Toerring@physik.fu-berlin.de wrote:
>
>
>
> Heh oh yes, strict_ansi has been changed since, forgot to change it in
> what I was pasting. As for the file name, I can’t find a thing wrong
> with it. In fact, someone also suggested that I should just remove the
> .h files from the dependency lists. When I do that it starts complaining
> about the .cpp files. Just now I've also tried using complete paths
> instead of relative ones... Same story. This thing is driving me crazy.
>
> All of the cxx lines run just fine. I manually went ahead and executed
> every cxx line in that file starting from the bottom and working my way
> up. Everything works just as it should. But when put into this make file
> I just don't know where it's looking for the dependencies that it
> doesn't find them.


Well, after a long day of working on this thing I finally got it to
work... Apparently, until I put spaces at the end of every line, it
couldn't find a thing. Oh, and it also wouldn't run the last line of the
file until I put an extra line feed. Right about now I would like to
kill the person who came up with this idea, but at least I'm happy that
it works now.

Thanks for your help anyway :)
Pascal Bourguignon

2004-09-27, 3:57 am

Max <max@mxserve.com> writes:

> Jens.Toerring@physik.fu-berlin.de wrote:
>
> Heh oh yes, strict_ansi has been changed since, forgot to change it in
> what I was pasting. As for the file name, I can’t find a thing wrong
> with it. In fact, someone also suggested that I should just remove the
> .h files from the dependency lists. When I do that it starts
> complaining about the .cpp files. Just now I've also tried using
> complete paths instead of relative ones... Same story. This thing is
> driving me crazy.
>
> All of the cxx lines run just fine. I manually went ahead and executed
> every cxx line in that file starting from the bottom and working my
> way up. Everything works just as it should. But when put into this
> make file I just don't know where it's looking for the dependencies
> that it doesn't find them.


Check the bytes in your makefile: use od -xa Makefile

Are you running on unix? You wrote it will, but I'd infer from such a
tense that you're using it on another OS for now? Then, what make do
you use? What file system do you use?

In what you pasted, there was no tabulation. On unix the make commands
usually expect a tabulation before the commands, and refuse
space. (Some legacy quirk).

On this Linux system, with GNU make, there's no problem, as long as
all the source files exist.

# cd /tmp/max/
# cat Makefile
cxx=@echo cxx

p1 : main.o DataManager.o EventList.o Event.o NameList.o Name.o
$(cxx) -w0 -std strict_ansi main.o DataManager.o EventList.o Event.o NameList.o Name.o -o p1

main.o : main.cpp DataManager.h Event.h Name.h
$(cxx) -w0 -std srtict_ansi -c main.cpp

DataManager.o : DataManager.cpp DataManager.h Event.h Name.h EventList.h
$(cxx) -w0 -std srtict_ansi -c DataManager.cpp

EventList.o : EventList.cpp EventList.h Event.h
$(cxx) -w0 -std srtict_ansi -c EventList.cpp

Event.o : Event.cpp Event.h NameList.h
$(cxx) -w0 -std srtict_ansi -c Event.cpp

NameList.o : NameList.cpp NameList.h Name.h
$(cxx) -w0 -std srtict_ansi -c NameList.cpp

Name.o : Name.cpp Name.h
$(cxx) -w0 -std srtict_ansi -c Name.cpp

touch:
@touch main.cpp DataManager.h Event.h Name.h Name.cpp Name.h NameList.cpp NameList.h Name.h EventList.cpp EventList.h Event.h DataManager.cpp DataManager.h Event.h Name.h EventList.h main.cpp DataManager.h Event.h Name.h Event.cpp

# make touch
# make
cxx -w0 -std srtict_ansi -c main.cpp
cxx -w0 -std srtict_ansi -c DataManager.cpp
cxx -w0 -std srtict_ansi -c EventList.cpp
cxx -w0 -std srtict_ansi -c Event.cpp
cxx -w0 -std srtict_ansi -c NameList.cpp
cxx -w0 -std srtict_ansi -c Name.cpp
cxx -w0 -std strict_ansi main.o DataManager.o EventList.o Event.o NameList.o Name.o -o p1


--
__Pascal Bourguignon__ http://www.informatimago.com/

Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we.
Paul D. Smith

2004-09-27, 3:57 am

%% Max <max@mxserve.com> writes:

m> Well, after a long day of working on this thing I finally got it to
m> work... Apparently, until I put spaces at the end of every line, it
m> couldn't find a thing. Oh, and it also wouldn't run the last line
m> of the file until I put an extra line feed. Right about now I would
m> like to kill the person who came up with this idea, but at least
m> I'm happy that it works now.

Almost certainly you wrote and perhaps are even maintaining your
makefile using a Windows editor instead of a UNIX editor.

Windows has a different line ending sequence than UNIX: on DOS and
Windows the line ending for a text file is delimited by two characters,
a carriage return (CR) and a line feed (LF). In UNIX there is only one
character signifying the line ending character: the line feed.


What this means is that if you try to use a Windows file directly on
UNIX with no translation, it looks to UNIX like all your lines have an
extra CR character appended to the end of them.

You don't mention what your operating system is or what version of make
you're using (always a serious mistake when asking for help on
newsgroups!), but if your version of make wasn't written specially to
understand Windows line endings then very likely it was interpreting the
extra CR character as part of the filename, and that's what caused your
problem.


The "fix" you employed worked one of two ways: either you changed the
file with a UNIX editor which stripped all the CRs for you, or adding
the extra space caused make to realize the CR wasn't part of the
filename, and it knew enough to ignore the single CR character and not
assume it was a filename.


Anyway, the moral here is use UNIX editors when working in UNIX
environments, and/or always remember to use a simple dos2unix utility
whenever you've been editing a UNIX file with a Windows editor.

--
-------------------------------------------------------------------------------
Paul D. Smith <psmith@gnu.org> Find some GNU make tips at:
http://www.gnu.org http://make.paulandlesley.org
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist
Nick Landsberg

2004-09-27, 3:57 am

Max wrote:
> Jens.Toerring@physik.fu-berlin.de wrote:
>=20
>=20
>=20
> Heh oh yes, strict_ansi has been changed since, forgot to change it in =


> what I was pasting. As for the file name, I can=92t find a thing wrong =


> with it. In fact, someone also suggested that I should just remove the =


> .h files from the dependency lists. When I do that it starts complainin=

g=20
> about the .cpp files. Just now I've also tried using complete paths=20
> instead of relative ones... Same story. This thing is driving me crazy.=


>=20
> All of the cxx lines run just fine. I manually went ahead and executed =


> every cxx line in that file starting from the bottom and working my way=

=20
> up. Everything works just as it should. But when put into this make fil=

e=20
> I just don't know where it's looking for the dependencies that it=20
> doesn't find them.


Make is rather fussy about layout. This is an off chance,
but are you sure there are tabs where there should be
tabs and spaces where there should be spaces?

Just a shot in the dark.


--=20
"It is impossible to make anything foolproof
because fools are so ingenious"
- A. Bloch
Sponsored Links







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

Copyright 2010 codecomments.com