Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

thealtered7

macrumors newbie
Original poster
Sep 11, 2007
8
0
Denver
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.
 

thealtered7

macrumors newbie
Original poster
Sep 11, 2007
8
0
Denver
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?
 

fimac

macrumors member
Jan 18, 2006
95
1
Finland
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).

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.
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
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)?
 

iSee

macrumors 68040
Oct 25, 2004
3,540
272
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.
 

thealtered7

macrumors newbie
Original poster
Sep 11, 2007
8
0
Denver
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....
 

thealtered7

macrumors newbie
Original poster
Sep 11, 2007
8
0
Denver
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.
 

zimv20

macrumors 601
Jul 18, 2002
4,402
11
toronto
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.