Make anomoly

Discussion in 'Mac Programming' started by thealtered7, Sep 11, 2007.

  1. thealtered7 macrumors newbie

    Joined:
    Sep 11, 2007
    Location:
    Denver
    #1
    I'm writing some simple C++ programs that don't require the full power of the XCode environment, so I'm using the Unix make program instead. However, I'm getting some strange behavior when I'm compiling. I'll run make, read the error messages, edit my code, then re run make. However, on the second running of make, no recognition of edits in my code takes place. I have to open a brand new terminal window, cd again to my source code directory and then and only then will any recognition of source code editing take place (errors go away).
    Has anybody else experienced this behavior with make? By the way, I'm using OS 10.4.10 with the g++ compiler that comes standard with Apple's development kits.
    Thanks.
     
  2. thealtered7 thread starter macrumors newbie

    Joined:
    Sep 11, 2007
    Location:
    Denver
    #2
    No one huh? I suppose with the power of xcode, nobody bothers with makefiles. However, I'll be turning in projects to professors who use Linux machines, so I thought I would use that paradigm. Now I think I'll just use xcode and create a makefile separately.
    Even if it is the case that nobody else has experienced this problem, does anybody have an idea of what might be causing this behavior?
     
  3. fimac macrumors member

    Joined:
    Jan 18, 2006
    Location:
    Finland
    #3
    Use "make -d" to get additional debugging information.

    If you want any further help, you will need to post a reduction: the smallest + simplest possible makefile and source files that exhibit the problem.
     
  4. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #4
    Have you tried using touch on the file you just edited?

    Have you tried using the -W <file> flag with make to force an updated build of the specified file (the same as using touch on the file)?
     
  5. iSee macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #5
    I've used make and not seen the problem you describe, so I don't think it is a general problem with make under OS X.

    This might sound like a dumb question, but are you sure you are saving your source code after making changes but before running make?

    These next two possibilities might not apply here, because it seems in your case that make is attempting to build the expected targets, but isn't picking up source code changes. But I list them just in case this is contributing:

    1. make works off of file modification dates, so take a look at the modification dates of the sources and targets in question. If these are out of whack for some reason, make will behave unexpectedly.

    2. Post your makefile in case the logic is out of whack.
     
  6. thealtered7 thread starter macrumors newbie

    Joined:
    Sep 11, 2007
    Location:
    Denver
    #6
    I was definately saving my files before compilations. I tested a number of other possibilities including different text editors for my edits. As I'm relatively new to writing Makefiles, I'm thinking the problem probably lies withing my logic.
    Here is my Makefile:
    ---------------------------------------------------

    CantusFirmus : ProgramMain.o Note.o Key.o Cantus_Firmus_Search.o
    g++ -o CantusFirmus ProgramMain.o Note.o Key.o Music_Exception.o Cantus_Firmus_Search.o

    ProgramMain.o : ProgramMain.cpp Note.h Key.h Music_Exception.h Music_Definitions.h Cantus_Firmus_Search.h
    g++ -c ProgramMain.cpp Note.cpp Key.cpp Cantus_Firmus_Search.cpp

    Cantus_Firmus_Search.o : Cantus_Firmus_Search.cpp Music_Exception.h Music_Definitions.h Key.h Note.h
    g++ -c Cantus_Firmus_Search.cpp Note.cpp Key.cpp

    Key.o : Key.cpp Key.h Note.h Music_Definitions.h
    g++ -c Key.cpp Note.cpp

    Note.o : Note.cpp Note.h Music_Definitions.h
    g++ -c Note.cpp

    --------------------------------------------------------------------
    I've never been formally taught how to use make, just read some stuff online. One more thing I have to get around to reading....
     
  7. lazydog macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #7
    Don't you need tab character at the start of each command line? I can't tell from your post if you have.

    b e n
     
  8. thealtered7 thread starter macrumors newbie

    Joined:
    Sep 11, 2007
    Location:
    Denver
    #8
    You are right, my post is incorrect. My actual Makefile does include the necessary tabs.
    Can anybody recommend a good Make tutorial for me? I can get it to function properly, but my makefile lack the grace and sophistication of the professional makefiles I observe.
     
  9. zimv20 macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    toronto
    #9
    it's not make, it's your makefile. you're missing a lot of stuff, and your dependencies are messed up. you don't say how you're invoking it, perhaps with make Cantus_Firus. i'd recommend an "all" target, and writing some rules so you don't have to be explicit with everything.

    this isn't tested (at all), but it should look something more like this:
    Code:
    CCC             =       g++
    
    RM		=	\rm -f
    RM_CMD                  =       $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut
    
    PROGRAM =       Cantus_Firus
    
    HEADERS =       Note.h \
                            Key.h
    
    SRCS    =       Note.cpp \
                            Key.cpp \
    			ProgramMain.cpp
    
    OBJS    =       ${SRCS:%.cpp=%.o}
    
    $(PROGRAM):     $(SRCS)
    
    all:            $(PROGRAM) $(OBJS)
    
    %.o: %.cpp
            $(RM) $@
            $(CCC) -c $(CFLAGS) $(_NOOP) -o $@ $<
    
    clean::
            $(RM_CMD) "#"*
    
    this is also pretty incomplete, but it's a better start, i think. you can then build you app simply by typing make, and you can also run make clean. i recommend the O'Reilly make book.
     
  10. thealtered7 thread starter macrumors newbie

    Joined:
    Sep 11, 2007
    Location:
    Denver
    #10
    Thanks. I'll add that to the long list of books I need to read on programming.
     

Share This Page