Help on makefiles

M

Max

I know this isn't directly related to C++, but thought I'd ask anyway.
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

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

(By the way, if the tabs don't stay, just know that they are there at
every cxx line). 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...

Thanks for any help.
 
J

Jacek Dziedzic

This is off-topic in this NG. However you might try to remove
all occurrences of .h files in your makefile, this should fix it.

HTH,
- J.
 
M

Max

Jacek said:
This is off-topic in this NG. However you might try to remove
all occurrences of .h files in your makefile, this should fix it.

HTH,
- J.

Thanks for that suggestion, but I already tried it right after posting
here. If I remove all .h files then it just complains about being unable
to make main.cpp.

Also, what newsgroup is best for this type of question?
 
D

Dan Mills

Max said:
Thanks for that suggestion, but I already tried it right after posting
here. If I remove all .h files then it just complains about being unable
to make main.cpp.

Daft thought, but you do know that unix is case sensitive right?
Also if cxx is anything like g++ then you need to specify the object name
when compiling or it will default to a.out which is probably not what you
want.

This this would be modified by adding a -oDataManager.o to the end of the
line starting <tab>cxx....

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

This is not your immediate problem but I thought it was worth mentioning.

Make bitching about not knowing how to make something that you have listed
as a dependency is usaually down to a typo in the name of the file.....
Also, what newsgroup is best for this type of question?

I would try comp.unix.programmer.

Regards, Dan.
 
E

E. Robert Tisdale

Max wrote:

[snip]
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.

make can't find Name.h
You misspelled it
or put it somewhere other than the directory where you invoked make.
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.

make can't find Name.h so it looks for a rule to make it.
 
M

Max

E. Robert Tisdale said:
Max wrote:

[snip]
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.


make can't find Name.h
You misspelled it
or put it somewhere other than the directory where you invoked make.
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.


make can't find Name.h so it looks for a rule to make it.
Any insight on what I'm doing wrong?
I never used makefiles before
so I'm sure there has to be something...

Here's the way my directory looks. As you can see all files are there
along with the makefile. I've already checked the spelling many times.
Still no luck :(

% ls
DataManager.cpp EventList.cpp Name.o main.cpp
DataManager.h EventList.h NameList.cpp main.o
DataManager.o EventList.o NameList.h my.output
Event.cpp Makefile NameList.o primary.input
Event.h Name.cpp a.out primary.output
Event.o Name.h cxx_repository
% make
.. Stop.n't know how to make Name.h
%

Btw, the .o files and a.out is what I got from just building the whole
thing manually. Make didn't generate those.
 
M

Max

Dan said:
Max wrote:




Daft thought, but you do know that unix is case sensitive right?
Also if cxx is anything like g++ then you need to specify the object name
when compiling or it will default to a.out which is probably not what you
want.

This this would be modified by adding a -oDataManager.o to the end of the
line starting <tab>cxx....

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

This is not your immediate problem but I thought it was worth mentioning.

Make bitching about not knowing how to make something that you have listed
as a dependency is usaually down to a typo in the name of the file.....




I would try comp.unix.programmer.

Regards, Dan.

All right, thanks. I'll try it there as well. But in the mean time, see
my reply to Robert. Don't think it's a typo and it's not due to letter
case either. Already checked all of that. As for a.out, the way I have
it right now is to build p1, but honestly if it gave me a.out I would be
very happy just as well. Just want it to give me something.
 
D

David Lindauer

I don't know about the first CXX line... is there really a line feed at the
end or is it just line wrapping because
you put it in a post? If it is the former that may be confusing make... I
don't know about unix make but the
make programs I have seen need a '\' if you are going to do line
continuation on another line.

David
E. Robert Tisdale said:
Max wrote:

[snip]
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.


make can't find Name.h
You misspelled it
or put it somewhere other than the directory where you invoked make.
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.


make can't find Name.h so it looks for a rule to make it.
Any insight on what I'm doing wrong?
I never used makefiles before
so I'm sure there has to be something...

Here's the way my directory looks. As you can see all files are there
along with the makefile. I've already checked the spelling many times.
Still no luck :(

% ls
DataManager.cpp EventList.cpp Name.o main.cpp
DataManager.h EventList.h NameList.cpp main.o
DataManager.o EventList.o NameList.h my.output
Event.cpp Makefile NameList.o primary.input
Event.h Name.cpp a.out primary.output
Event.o Name.h cxx_repository
% make
. Stop.n't know how to make Name.h
%

Btw, the .o files and a.out is what I got from just building the whole
thing manually. Make didn't generate those.
 
M

Max

David said:
I don't know about the first CXX line... is there really a line feed at the
end or is it just line wrapping because
you put it in a post? If it is the former that may be confusing make... I
don't know about unix make but the
make programs I have seen need a '\' if you are going to do line
continuation on another line.

David

No line feed there. Might just be your screen resolution. This does look
more like make doesn't recognize that Name.h is a file, but I have no
idea what I can do about it... I even tried specifying complete paths to
those files, not relative ones. Same story.
 
E

E. Robert Tisdale

Max said:
Here's the way my directory looks.
As you can see all files are there along with the makefile.
I've already checked the spelling many times.
Still no luck :(

% ls
DataManager.cpp EventList.cpp Name.o main.cpp
DataManager.h EventList.h NameList.cpp main.o
DataManager.o EventList.o NameList.h my.output
Event.cpp Makefile NameList.o primary.input
Event.h Name.cpp a.out primary.output
Event.o Name.h cxx_repository
% make
. Stop.n't know how to make Name.h
%

Btw, the .o files and a.out is what I got from just building the whole
thing manually. Make didn't generate those.
DataManager.cpp Event.h main.cpp Name.h
DataManager.h EventList.cpp Makefile NameList.cpp
Event.cpp EventList.h Name.cpp NameList.h
expand Makefile
p1: main.o DataManager.o EventList.o Event.o \
NameList.o Name.o
g++ -Wall -ansi -pedantic \
main.o DataManager.o EventList.o Event.o NameList.o Name.o -o
p1

main.o: main.cpp DataManager.h Event.h Name.h
g++ -Wall -ansi -pedantic -c main.cpp

DataManager.o: DataManager.cpp DataManager.h Event.h Name.h \
EventList.h
g++ -Wall -ansi -pedantic -c DataManager.cpp

EventList.o: EventList.cpp EventList.h Event.h
g++ -Wall -ansi -pedantic -c EventList.cpp

Event.o: Event.cpp Event.h NameList.h
g++ -Wall -ansi -pedantic -c Event.cpp

NameList.o: NameList.cpp NameList.h Name.h
g++ -Wall -ansi -pedantic -c NameList.cpp

Name.o: Name.cpp Name.h
g++ -Wall -ansi -pedantic -c Name.cpp

clean:
rm -f p1 *.o
g++ -Wall -ansi -pedantic -c main.cpp
g++ -Wall -ansi -pedantic -c DataManager.cpp
g++ -Wall -ansi -pedantic -c EventList.cpp
g++ -Wall -ansi -pedantic -c Event.cpp
g++ -Wall -ansi -pedantic -c NameList.cpp
g++ -Wall -ansi -pedantic -c Name.cpp
g++ -Wall -ansi -pedantic \
main.o DataManager.o EventList.o Event.o NameList.o Name.o -o p1
DataManager.cpp EventList.cpp main.o NameList.h
DataManager.h EventList.h Makefile NameList.o
DataManager.o EventList.o Name.cpp Name.o
Event.cpp Event.o Name.h p1
Event.h main.cpp NameList.cpp

It seems to work just fine for me.

Did you notice that you misspelled strict_ansi
in every target after the first?
 
M

Max

Well guys, 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 all your help :)
 
M

Max

E. Robert Tisdale said:
It seems to work just fine for me.

Did you notice that you misspelled strict_ansi
in every target after the first?

Yea, those I fixed. See my reply to the original post. It was all
because I didn't have any spaces at the end of each line, and also
because I didn't have an extra line at the end of the file.
 
P

Phlip

Max said:
Still no luck :(

% ls
^

You need to configure your shell - probably by setting PS1 - to reflect your
current folder. That makes BASHing (or using whatever SHell you use) a
little easier.

(BTW you have probably been warned this question is off topic. Hence we can
answer any part of it we feel like ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top