Dragonfly Q&A

Makefile issues

0 like 0 dislike

I can't seem to get my makefile working, I made all the modifications described in the book but I still get errors.  Below is the makefile:

CC= g++ 
PLATFORM= -DCYGWIN # uncomment for cygwin
#PLATFORM= -DMACOS   # uncomment for macos
LDFLAGS= -lncurses -lrt # uncomment linux/cygwin
#LDFLAGS= -lncurses # uncomment for macos
#INCPATH= include # path to engine includes
#ENG= lib/libdragonfly.a # dragonfly engine
ENGSRC= Manager.cpp LogManager.cpp
GAME= game.cpp
EXECUTABLE= game
OBJECTS= $(ENGSRC:.cpp=.o)
 
all: $(EXECUTABLE) Makefile
 
$(EXECUTABLE): $(OBJECTS) $(GAME) $(ENGSRC)
$(CC) $(GAME) $(OBJECTS) -o $@ $(LDFLAGS)
 
.cpp.o: 
$(CC) -c $(DEBUG) $< -o $@
 
clean:
rm -rf $(OBJECTS) $(EXECUTABLE) core dragonfly.log Makefile.bak *~
 
depend: 
makedepend *.cpp 2> /dev/null
 
It seems to compile Manager and LogManager fine, but fails when putting together all the files with game.cpp.
asked Sep 13, 2014 by lrodonnell

2 Answers

0 like 0 dislike

Your Makefile looks ok, but it is hard to debug visually.  Do you have a tab in front of your .cpp.o recipe?  i.e., it should be:

.cpp.o:

<TAB_HERE>$(CC) -c $(DEBUG) $< -o $@

Ditto for the clean: and depend: entries.   Assuming those are fine, what is the compile command  you get when building game?  It should look like:

g++  game.cpp Manager.o LogManager.o -o game

Assuming it looks like that, what is the error message you are getting?
 

answered Sep 13, 2014 by claypool
Just mentioning to you, you can add a new category, called "Help" or "Problem", for these types of questions. It will be easier to sort them in the future.
Thanks for the suggestion.  I'm waiting to see what question categories seem to emerge naturally before adding too many more.  I did just add an "Other" category now.
I do have the tabs on each entry.  The command i get is "g++ game.cpp Manager.o LogManager.o -o game -lncurses -lrt"
The error is long, it involves "undefined reference to "LogManager::getInstance()" which sounds like the header files are not being connected correctly perhaps?  The end of the error reads "recipe for target 'game' failed"
That all sounds good.  I don't think the problem is your Makefile.  It sounds like your LogManager hasn't declared and defined getInstance() properly.  Double check that it is public. Also, make sure it isn't spelled differently (no typo).  

If all those check out, please zip up all your code and email it to the staff mailing list.  We can take a look.
Thank you very much, this was the problem (undefined functions that were in the header but not the source).
0 like 0 dislike
If we're posting codes, we should use Pastebin instead. This forum software does not support code syntax tags, usually seen in vBulletin and Xenforos.

When compiling your codes using the Makefile, be sure to compile with all references to $(OBJECTS) removed.

In my case, I explicitly tell "make" not to include my $(OBJECTS) into compilation command line.

Here's an example of what I used for my Makefile:

http://pastebin.com/ci4sA4cu
answered Sep 13, 2014 by tom_mai78101
More information about Dragonfly can be found on the Dragonfly Home Page.
...