#27409 - SmegPlaza - Tue Oct 12, 2004 1:44 pm
Hi,
First of all let me say I am not a noob. I have years of experience of coding on various platforms, including PC and Amiga, and am equally happy using command line driven tools as I am using an IDE like Visual C++.
But for some reason I am having great difficulty getting DevKitAdvance to do what I want it to do... So much so that I am almost at the point of giving up on it and moving to something else.
I am, I think, sufficiently modest, to believe that it must be me that's doing something wrong, because plenty of other people seem to have far fewer problems.
I have a project which I am trying to port to the GBA, written in mixed C and assembly language, so I am trying to get it to build using a makefile rather than the batch file commonly used for simpler projects.
Compilation and assembly of my source files is no problem - everything compiles and assembles just fine. Linking is where I have all my issues, and they all seem to revolve around symbols and functions from the run-time and support libraries i.e. not my code.
There seem to be so many different versions of the run-time support libraries crt0.o and libc.a, for example, even given the ARM/THUMB distinctions, that I'm not sure I am linking with the correct version.
So my question is simple :)
Can anyone please tell me, for a THUMB-only build, for example, *exactly* which versions of crt0.c, libc.a and libgcc.a I should be linking with ?
An example makefile for for a non-trivial application would be useful as well ;)
Thanks in advance,
Smeg
#27416 - Abscissa - Tue Oct 12, 2004 3:18 pm
Well, for one thing, you should use DevKitARM instead of DevKitAdvance. DevKitAdvance hasn't been updated in a long time and seems to be abandoned. You can find DevKitARM at http://www.devkit.tk
#27417 - tepples - Tue Oct 12, 2004 3:39 pm
The "R8" (rather than "R5 beta 3") seems to make me think that SmegPlaza is talking about devkitARM but saying DevKit Advance.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#27468 - SmegPlaza - Wed Oct 13, 2004 4:07 pm
Yes guys, it is DevKitARM R8... my mistake :)
Smeg
#27471 - DiscoStew - Wed Oct 13, 2004 6:20 pm
What are the libraries compiled with? Just a guess since I don't know how the format goes when code is compiled into OBJ and library files, but I'm thinking that the libraries you have may not be compatible with the ARM7 CPU that the GBA has. Remember, it's just a guess since I saw the word "port" along with "libraries", but I'm probably wrong. Reminds me of using OBJ files made by Borland compilers to use in MS VC++, which doesn't work.
As for linking files like crt0.o and libc.a, I don't have any of that in my project folders, so I'm assuming that these are added by default from the DevKitARM folder.
I could show you the makefile that I have if you'd like. It allows for adding libraries, and splitting source files to be put into IWRAM/ARM or ROM/THUMB, and even making a multiboot ROM with a single change. It is a modified version of another makefile that I found, so I can't take all the credit. Ask, and ye shall receive.
_________________
DS - It's all about DiscoStew
#27478 - SmegPlaza - Wed Oct 13, 2004 8:52 pm
Discostew,
That would be very helpful, thank you !
I've been tearing my hair out with this, cos it *should* be easy !!!
Cheers bud,
Smeg
PS. Should I be using the tools & libs in the 'arm-elf' directory, or the ones in the bin and lib dirs ???
#27481 - DiscoStew - Wed Oct 13, 2004 9:38 pm
The makefile shown here is what I use for my GBA development, which I use VS.net as my IDE. It also adds the AAS library made by jd for the audio department. I believe you have already looked how to set up DevKitARM from its main website, so I'll skip that. You'll need to change the PATH symbol to whereever you installed DevKitARM, but make sure it has"\bin" because that is where the tools are. Then all you'll need to do is copy this code into a makefile called "Makefile", no extension. In your individual project folder, create "src" and "header" folders, and place all source code (c, cpp, s) into "src", and all headers into "header". If you want to add libraries, follow the examples I placed in here on how to add them. If you are making a C++ project, replace the LD symbol with the other. That should be it. Hopefully you get your stuff working.
Code: |
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
#---------------------------------------------------------------------------------
# TARGET is the name of the output, if this ends with _mb generates a multiboot image
# 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 := Test
BUILD := build
SOURCES := src
INCLUDES := header
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
CFLAGS := -mthumb-interwork -Wall -mcpu=arm7tdmi -mtune=arm7tdmi \
-fomit-frame-pointer -ffast-math -mapcs-32 -fno-exceptions -std=c99
THUMB := -mthumb -O3 -ffixed-r14 -funroll-loops
ARM := -marm -O3 -mlong-calls
ASFLAGS := -mthumb-interwork
LDFLAGS = -mthumb-interwork
#---------------------------------------------------------------------------------
# place any libraries to be used here, one row per library would be best
#---------------------------------------------------------------------------------
#LIBNAME := ..//LibNAME
LIBAAS := ../LibAAS
#---------------------------------------------------------------------------------
# other commands for libraries we wish to link with the project
#---------------------------------------------------------------------------------
#LIBS := -lNAME -lNAME2 -lNAME3
LIBS := -lAAS
#LIBDIRS := $(LIBNAME) $(LIBNAME2) $(LIBNAME3)
LIBDIRS := $(LIBAAS)
#---------------------------------------------------------------------------------
# path to tools - this can be deleted if you set the path in windows
#---------------------------------------------------------------------------------
export PATH := /c/GBA/DevKitARM/bin:/bin:/c/bin
#---------------------------------------------------------------------------------
# the prefix on the compiler executables
#---------------------------------------------------------------------------------
PREFIX := arm-elf-
#---------------------------------------------------------------------------------
# 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))
export CC := $(PREFIX)gcc
export CXX := $(PREFIX)g++
export AR := $(PREFIX)ar
export AS := $(PREFIX)as
export OBJCOPY := $(PREFIX)objcopy
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
#export LD := $(CXX)
export LD := $(CC)
BINFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.bin)))
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINOBJS := $(BINFILES:.bin=.o)
COBJS := $(CFILES:.c=.o)
CPPOBJS := $(CPPFILES:.cpp=.o)
SOBJS := $(SFILES:.s=.o)
export OFILES := $(BINOBJS) $(COBJS) $(CPPOBJS) $(SOBJS)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir))
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) *.elf
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).gba : $(OUTPUT).elf
$(OUTPUT).elf : $(OFILES)
#---------------------------------------------------------------------------------
%.gba: %.elf
@echo built ... $(notdir $@)
@$(OBJCOPY) -O binary $< $@
@gbafix $@
#---------------------------------------------------------------------------------
%_mb.elf:
@echo linking multiboot
@$(LD) -specs=gba_mb.specs $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
#---------------------------------------------------------------------------------
%.elf:
@echo linking cartridge
@$(LD) -specs=gba.specs $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
#---------------------------------------------------------------------------------
# Compile Targets for C/C++/ASM
#---------------------------------------------------------------------------------
#---------------------------------------------------------------------------------
%.iwram.o : %.iwram.c
@echo $(notdir $<)
@$(CC) $(ARM) $(CFLAGS) $(INCLUDE) -c $< -o $@
#---------------------------------------------------------------------------------
%.o : %.c
@echo $(notdir $<)
@$(CC) $(THUMB) $(CFLAGS) $(INCLUDE) -c $< -o $@
#---------------------------------------------------------------------------------
%.iwram.o : %.iwram.cpp
@echo $(notdir $<)
@$(CC) $(ARM) $(CFLAGS) $(INCLUDE) -c $< -o $@
#---------------------------------------------------------------------------------
%.o : %.cpp
@echo $(notdir $<)
@$(CC) $(THUMB) $(CFLAGS) $(INCLUDE) -c $< -o $@
#---------------------------------------------------------------------------------
%.o : %.s
@echo $(notdir $<)
@$(AS) $(ASFLAGS) $< -o $@
#---------------------------------------------------------------------------------------
define bin2o
cp $(<) $(*).tmp
$(OBJCOPY) -I binary -O elf32-littlearm -B arm \
--rename-section .data=.rodata,readonly,data,contents \
--redefine-sym _binary_$*_tmp_start=$*\
--redefine-sym _binary_$*_tmp_end=$*_end\
--redefine-sym _binary_$*_tmp_size=$*_size\
$(*).tmp $(@)
echo "extern const u8" $(*)"[];" > $(*).h
echo "extern const u32" $(*)_size[]";" >> $(*).h
rm $(*).tmp
endef
#---------------------------------------------------------------------------------
%.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
|
_________________
DS - It's all about DiscoStew
#27485 - SmegPlaza - Wed Oct 13, 2004 10:22 pm
Thanks DiscoStew.
You've been a great help...
Smeg