Welcome! Log In Create A New Profile

Advanced

Makefile and compiling help

Posted by ramonimbao 
Makefile and compiling help
April 10, 2009 08:41AM
Hello, everyone. I'm trying to port rRootage for the Wii. I already changed a few things in rRootage's code. It builds fine but whenever it gets to the linking part, BOOM!, my console gets flooded with errors. It's all an "undefined reference to [function name here]". I check the file, it looks fine, but (I think) the functions are only being called at a later time.

In the Makefile, it has this certain part:
OBJS =	$(NAME).$(O) \
	foe.$(O) foecommand.$(O) barragemanager.$(O) boss.$(O) ship.$(O) laser.$(O) \
	frag.$(O) background.$(O) letterrender.$(O) shot.$(O) \
	screen.$(O) vector.$(O) degutil.$(O) rand.$(O) mt19937int.$(O) \
	soundmanager.$(O) attractmanager.$(O) \
	$(NAME)_res.$(O)

That does mean that it has to compile those files in that certain order, right? Correct me if I'm wrong.
So how do I make the compiler (well...) compile the files in that order?

I'm not incredibly familiar with C/C++, you know, learning it slowly on and off for months, so forgive me if my terms are not correct.
Re: Makefile and compiling help
April 10, 2009 04:58PM
OBJS =	$(NAME).$(O) \
	foe.$(O) foecommand.$(O) barragemanager.$(O) boss.$(O) ship.$(O) laser.$(O) \
	frag.$(O) background.$(O) letterrender.$(O) shot.$(O) \
	screen.$(O) vector.$(O) degutil.$(O) rand.$(O) mt19937int.$(O) \
	soundmanager.$(O) attractmanager.$(O) \
	$(NAME)_res.$(O)
Don't think I've ever seen it done like that. I'm assuming the above files are all of your source code? Would you mind posting the entire makefile so we can see where the above block is located? Have you tried commenting the above block of code out, then recompiling to see if it gives same errors in linking?
Re: Makefile and compiling help
April 10, 2009 06:12PM
No. That's the Makefile of the Windows version of rRootage.
The Makefile I'm using is the template Makefile.
Re: Makefile and compiling help
April 10, 2009 06:37PM
Hm...ok lemme see your entire Wii makefile...gotta be something weird (and probably simple).
Re: Makefile and compiling help
April 11, 2009 05:44AM
Okay. Here it is.

#---------------------------------------------------------------------------------
# Clear the implicit built in rules
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC")
endif

include $(DEVKITPPC)/wii_rules

#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
#---------------------------------------------------------------------------------
TARGET		:=	$(notdir $(CURDIR))
BUILD		:=	build
SOURCES		:=	source
DATA		:=	data  
INCLUDES	:=

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------

CFLAGS	= -g -O2 -Wall $(MACHDEP) $(INCLUDE)
CXXFLAGS	=	$(CFLAGS)

LDFLAGS	=	-g $(MACHDEP) -Wl,-Map,$(notdir $@).map

#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS	:=	-lgl2gx -lfreetype -ljpeg -lpng -lz -lSDL -lfat -lwiiuse -lbte -logc -lm

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS	:=

#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------

export OUTPUT	:=	$(CURDIR)/$(TARGET)

export VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
					$(foreach dir,$(DATA),$(CURDIR)/$(dir))

export DEPSDIR	:=	$(CURDIR)/$(BUILD)

#---------------------------------------------------------------------------------
# automatically build a list of object files for our project
#---------------------------------------------------------------------------------
CFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
sFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
BINFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))

#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
	export LD	:=	$(CC)
else
	export LD	:=	$(CXX)
endif

export OFILES	:=	$(addsuffix .o,$(BINFILES)) \
					$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
					$(sFILES:.s=.o) $(SFILES:.S=.o)

#---------------------------------------------------------------------------------
# build a list of include paths
#---------------------------------------------------------------------------------
export INCLUDE	:=	$(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \
					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
					-I$(CURDIR)/$(BUILD) \
					-I$(LIBOGC_INC)

#---------------------------------------------------------------------------------
# build a list of library paths
#---------------------------------------------------------------------------------
export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
					-L$(LIBOGC_LIB)

export OUTPUT	:=	$(CURDIR)/$(TARGET)
.PHONY: $(BUILD) clean

#---------------------------------------------------------------------------------
$(BUILD):
	@[ -d $@ ] || mkdir -p $@
	@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

#---------------------------------------------------------------------------------
clean:
	@echo clean ...
	@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol

#---------------------------------------------------------------------------------
run:
	wiiload $(TARGET).dol


#---------------------------------------------------------------------------------
else

DEPENDS	:=	$(OFILES:.o=.d)

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).dol: $(OUTPUT).elf
$(OUTPUT).elf: $(OFILES)

#---------------------------------------------------------------------------------
# This rule links in binary data with the .jpg extension
#---------------------------------------------------------------------------------
%.jpg.o	:	%.jpg
#---------------------------------------------------------------------------------
	@echo $(notdir $<)
	$(bin2o)

-include $(DEPENDS)

#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------

I removed the "-lSDL_ttf -lSDL_gfx -lSDL_mixer -lSDL_image" part of the Makefile because it doesn't compile.

EDIT: That's weird. Yesterday, there were no errors saying "undefined reference to [insert GL function here]". When I tried compiling it again, those just started comping up. And what's weirder is that the errors only apply to certain parts of the file. Other parts (in which the same function is used) do no have errors. Help?



Edited 1 time(s). Last edit at 04/11/2009 06:00AM by ramonimbao.
Re: Makefile and compiling help
April 11, 2009 05:57AM
Okay, the makefile looks fine to me. What kind of linking errors are you getting? It might be the gl2gx, cus I always have problems compiling that stuff.
Re: Makefile and compiling help
April 11, 2009 07:33AM
Yeah. There are a few gl2gx errors seen.
rr.o: In function `parseArgs':
C:/devkitpro/projects/rr/source/rr.c:221: undefined reference to `nowait'
screen.o: In function `drawCircle':
C:/devkitpro/projects/rr/source/screen.c:481: undefined reference to `glColor4ub'
C:/devkitpro/projects/rr/source/screen.c:490: undefined reference to `glColor4ub'
C:/devkitpro/projects/rr/source/screen.c:483: undefined reference to `glColor4ub'
screen.o: In function `drawLaser':
C:/devkitpro/projects/rr/source/screen.c:321: undefined reference to `glColor4ub'
C:/devkitpro/projects/rr/source/screen.c:324: undefined reference to `glColor4ub'
screen.o:C:/devkitpro/projects/rr/source/screen.c:326: more undefined references
 to `glColor4ub' follow
screen.o: In function `drawBoard':
C:/devkitpro/projects/rr/source/screen.c:788: undefined reference to `glVertex2f'
C:/devkitpro/projects/rr/source/screen.c:789: undefined reference to `glVertex2f'
C:/devkitpro/projects/rr/source/screen.c:790: undefined reference to `glVertex2f'
C:/devkitpro/projects/rr/source/screen.c:791: undefined reference to `glVertex2f'
screen.o: In function `screenResized':
C:/devkitpro/projects/rr/source/screen.c:39: undefined reference to `glViewport'

C:/devkitpro/projects/rr/source/screen.c:40: undefined reference to `glMatrixMode'
C:/devkitpro/projects/rr/source/screen.c:43: undefined reference to `glMatrixMode'
screen.o: In function `startDrawBoards':
C:/devkitpro/projects/rr/source/screen.c:771: undefined reference to `glMatrixMode'
C:/devkitpro/projects/rr/source/screen.c:774: undefined reference to `glOrtho'
C:/devkitpro/projects/rr/source/screen.c:775: undefined reference to `glMatrixMode'
screen.o: In function `drawBox':
C:/devkitpro/projects/rr/source/screen.c:210: undefined reference to `glColor4ub'
C:/devkitpro/projects/rr/source/screen.c:217: undefined reference to `glColor4ub'
screen.o: In function `drawShot':
C:/devkitpro/projects/rr/source/screen.c:749: undefined reference to `glColor4ub'
C:/devkitpro/projects/rr/source/screen.c:759: undefined reference to `glColor4ub'
C:/devkitpro/projects/rr/source/screen.c:763: undefined reference to `glColor4ub'
screen.o:C:/devkitpro/projects/rr/source/screen.c:429: more undefined references to `glColor4ub' follow
screen.o: In function `loadGLTexture':
C:/devkitpro/projects/rr/source/screen.c:87: undefined reference to `glTexParameteri'
C:/devkitpro/projects/rr/source/screen.c:88: undefined reference to `glTexParameteri'
C:/devkitpro/projects/rr/source/screen.c:89: undefined reference to `gluBuild2DMipmaps'
screen.o: In function `initGL':
C:/devkitpro/projects/rr/source/screen.c:53: undefined reference to `glViewport'
C:/devkitpro/projects/rr/source/screen.c:56: undefined reference to `glLineWidth'
C:/devkitpro/projects/rr/source/screen.c:59: undefined reference to `glBlendFunc'

Those are the only gl2gx errors. The rest are actually void() functions.
EDIT: Okay. So I fixed one of my errors. I didn't include -lSDL_ libraries. It turns out. I needed -lSDL_mixer. The other errors are still there, though.



Edited 1 time(s). Last edit at 04/11/2009 07:37AM by ramonimbao.
Sorry, only registered users may post in this forum.

Click here to login