Help on makefiles

Discussion in 'C++' started by Max, Sep 26, 2004.

  1. Max

    Max Guest

    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.
     
    Max, Sep 26, 2004
    #1
    1. Advertising

  2. Re: [OT] Help on makefiles

    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.
     
    Jacek Dziedzic, Sep 26, 2004
    #2
    1. Advertising

  3. Max

    Max Guest

    Re: [OT] Help on makefiles

    Jacek Dziedzic wrote:
    >
    > 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?
     
    Max, Sep 26, 2004
    #3
  4. Max

    Dan Mills Guest

    Re: [OT] Help on makefiles

    Max wrote:

    >
    > 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.
    --
    ** The email address *IS* valid, do NOT remove the spamblock
    And on the evening of the first day the lord said...........
    ..... LX 1, GO!; and there was light.
     
    Dan Mills, Sep 27, 2004
    #4
  5. 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...
     
    E. Robert Tisdale, Sep 27, 2004
    #5
  6. Max

    Max Guest

    E. Robert Tisdale wrote:
    > 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.
     
    Max, Sep 27, 2004
    #6
  7. Max

    Max Guest

    Re: [OT] Help on makefiles

    Dan Mills wrote:

    > Max wrote:
    >
    >
    >>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.


    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.
     
    Max, Sep 27, 2004
    #7
  8. 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

    Max wrote:

    > E. Robert Tisdale wrote:
    > > 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.
     
    David Lindauer, Sep 27, 2004
    #8
  9. Max

    Max Guest

    David Lindauer wrote:
    > 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.
     
    Max, Sep 27, 2004
    #9
  10. Max wrote:

    > 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.


    > ls -w 70

    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

    > make

    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
    > ls -w 60

    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?
     
    E. Robert Tisdale, Sep 27, 2004
    #10
  11. Max

    Max Guest

    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 :)
     
    Max, Sep 27, 2004
    #11
  12. Max

    Max Guest

    E. Robert Tisdale wrote:
    >
    > 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.
     
    Max, Sep 27, 2004
    #12
  13. Max

    Phlip Guest

    Re: [OT] Help on makefiles

    Max wrote:

    > 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 ;-)

    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
     
    Phlip, Sep 27, 2004
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sasquatch

    Makefiles for JAVA

    sasquatch, Nov 8, 2003, in forum: Java
    Replies:
    5
    Views:
    751
    Dale King
    Nov 12, 2003
  2. Harris L

    Ant vs Makefiles

    Harris L, Nov 26, 2004, in forum: Java
    Replies:
    20
    Views:
    10,774
    Jacob
    Dec 2, 2004
  3. dharmesh Gupta

    Making of Makefiles

    dharmesh Gupta, Aug 26, 2003, in forum: C++
    Replies:
    2
    Views:
    342
    Kevin Goodsell
    Aug 26, 2003
  4. Janne Naukkarinen
    Replies:
    1
    Views:
    373
    Jack Klein
    Jan 15, 2004
  5. db
    Replies:
    2
    Views:
    433
Loading...

Share This Page