#145444 - modchamp - Thu Nov 15, 2007 7:01 pm
Well I'm once again hooked on the gbamp and since I want to get into DS programming I thought I'd start with GBA programming as it seems much simpler. Anyways I really have no idea what I'm doing at this point so I'd like a little help.
OS: Windows XP Home Service Pack 2
Compiler: DevkitPro 1.4.4
Installation Location: c:\devkitPro AND c:\devkitPro\devkitARM
Here's my test C file:
Code: |
/*
Turn the screen green!
Platform: GBA
Author: Damian Yerrick
Copyright: All rights released
*/
typedef unsigned int u16;
#define BG_COLORS ((u16 *)0x05000000)
#define REG_DISPCNT (*(u16 *)0x04000000)
#define RGB5(r,g,b) ((r)|((g)<<5)|((b)<<10))
int main(void) {
REG_DISPCNT = 0; // mode 0, no backgrounds or sprites
BG_COLORS[0] = RGB5(0, 31, 0);
while (1) {}
} |
Here's my test batch file:
Code: |
set Path=c:\devkitPro\devkitARM\bin
arm-eabi-gcc -Wall -mthumb -mthumb-interwork test.c -o test.elf -specs=gba_mb.specs
arm-eabi-objcopy -O binary test.elf test.gba
gbafix test.gba
pause |
And here's the error I'm getting when I try and run the batch file:
[Images not permitted - Click here to view it]
If more information is required to help me, let me know and I'd be glad to post it. All help is greatly appreciated.
Thanks,
-Modchamp
#145446 - NeX - Thu Nov 15, 2007 7:14 pm
May I ask why you are using a command line to compile? I never have done, on the PC, GBA or DS.
_________________
Strummer or Drummer?.
Or maybe you would rather play with sand? Sandscape is for you in that case.
#145448 - modchamp - Thu Nov 15, 2007 7:17 pm
How do you suggest I compile it then? To me it seemed that a batch file was the easiest and fastest way to compile and recompile things.
#145452 - NeX - Thu Nov 15, 2007 7:29 pm
Well, in whatever editor I am using, I simply hit the "Compile" or "Make" button.
_________________
Strummer or Drummer?.
Or maybe you would rather play with sand? Sandscape is for you in that case.
#145453 - modchamp - Thu Nov 15, 2007 7:31 pm
Lol mind being a little more helpful?
Could you please tell me which program your using, and maybe even give me an example of how you go about compiling with it?
#145456 - gauauu - Thu Nov 15, 2007 8:42 pm
NeX wrote: |
May I ask why you are using a command line to compile? I never have done, on the PC, GBA or DS. |
The command line is a fine way to compile (although I would recommend makefiles instead of batch files, but that's less important for an immediate "check to see if the toolchain works"). If you are using the magic "build" buttons of an editor or IDE, you still have to have your toolchain environment set up correctly.
That being said, modchamp, is there a directory called c:\devkitPro\msys? Depending on how you installed devkitPro, it should have gotten installed as well. Try adding c:\devkitPro\msys\bin to your path as well, and see if that helps.
I'm not an expert on the toolchain setup (I got mine working, and left it at that). So hopefully someone smarter will come along and answer if I'm totally off.
#145457 - modchamp - Thu Nov 15, 2007 8:50 pm
Ok I change my set Path to:
Code: |
set Path=c:\devkitPro\devkitARM\bin;c:\devkitPro\devkitmsys\bin |
still getting the same error though.
Also I really don't like makefiles ^_^ But if they would work I'd use them too, got an example of a makefile I could try?
#145458 - bean_xp - Thu Nov 15, 2007 10:10 pm
Just use the ones included in the DevKitPro examples they should work fine for most cases.
#145459 - modchamp - Thu Nov 15, 2007 10:28 pm
Ok I found the devkitpro example and here is what I've got:
C source code
Code: |
#include <gba_console.h>
#include <gba_video.h>
#include <gba_interrupt.h>
#include <gba_systemcalls.h>
#include <gba_input.h>
#include <stdio.h>
#include <stdlib.h>
int frame = 0;
void Vblank() {
frame++;
}
//---------------------------------------------------------------------------------
// Program entry point
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
// the vblank interrupt must be enabled for VBlankIntrWait() to work
// since the default dispatcher handles the bios flags no vblank handler
// is required
irqInit();
irqSet(IRQ_VBLANK, Vblank);
irqEnable(IRQ_VBLANK);
consoleInit( 0 , 4 , 0, NULL , 0 , 15);
BG_COLORS[0]=RGB8(58,110,165);
BG_COLORS[241]=RGB5(31,31,31);
SetMode(MODE_0 | BG0_ON);
// ansi escape sequence to set print co-ordinates
// /x1b[line;columnH
iprintf("\x1b[10;10HHello World!\n");
iprintf("%x",malloc(200));
while (1) {
VBlankIntrWait();
scanKeys();
}
}
|
Makefile:
Code: |
#---------------------------------------------------------------------------------
# Clear the implicit built in rules
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM)
endif
include $(DEVKITARM)/gba_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output, if this ends with _mb a multiboot image is generated
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))_mb
BUILD := build
SOURCES := source
DATA :=
INCLUDES :=
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -mthumb -mthumb-interwork
CFLAGS := -g -Wall -O3\
-mcpu=arm7tdmi -mtune=arm7tdmi\
-fomit-frame-pointer\
-ffast-math \
$(ARCH)
CFLAGS += $(INCLUDE)
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := $(ARCH)
LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir $@).map
#---------------------------------------------------------------------------------
# path to tools - this can be deleted if you set the path to the toolchain in windows
#---------------------------------------------------------------------------------
export PATH := $(DEVKITARM)/bin:$(PATH)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lgba
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBGBA)
#---------------------------------------------------------------------------------
# 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)))
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)
#---------------------------------------------------------------------------------
# build a list of include paths
#---------------------------------------------------------------------------------
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
#---------------------------------------------------------------------------------
# build a list of library paths
#---------------------------------------------------------------------------------
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
all : $(BUILD)
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).gba
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).gba : $(OUTPUT).elf
$(OUTPUT).elf : $(OFILES)
-include $(DEPENDS)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
|
When I click make in Programmers Notepad I get this:
Quote: |
> "make"
template.c
arm-eabi-gcc -MMD -MP -MF /c/devkitpro/examples/gba/template/build/template.d -g -Wall -O3 -mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer -ffast-math -mthumb -mthumb-interwork -I/c/devkitPro/libgba/include -I/c/devkitpro/examples/gba/template/build -c /c/devkitpro/examples/gba/template/source/template.c -o template.o
/c/devkitPro/devkitARM/bin/arm-eabi-gcc: /c/devkitPro/devkitARM/bin/arm-eabi-gcc: cannot execute binary file
make[1]: *** [template.o] Error 126
"make": *** [build] Error 2
> Process Exit Code: 2
> Time Taken: 00:00 |
What did I do wrong?
#145500 - gauauu - Fri Nov 16, 2007 8:28 pm
modchamp wrote: |
Ok I change my set Path to:
Code: | set Path=c:\devkitPro\devkitARM\bin;c:\devkitPro\devkitmsys\bin |
|
Again, I don't really know...but since nobody else has responded....
Is this:
Code: |
c:\devkitPro\devkitmsys\bin |
just a typo?
do you mean:
Code: |
c:\devkitPro\msys\bin |
#145501 - modchamp - Fri Nov 16, 2007 8:48 pm
Ahh yes your right.
Well fixed that and now I'm getting this:
[Images not permitted - Click here to view it]
#145601 - wintermute - Sun Nov 18, 2007 9:44 pm
That looks like you have old files from devkitARM r18 in your installation.
Have a look in devkitARM/arm-eabi/bin and delete the ld file in there - note: ld not ld.exe.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog
#145603 - modchamp - Sun Nov 18, 2007 10:05 pm
Thanks so much it worked. :D
#145631 - anox - Mon Nov 19, 2007 5:02 pm
Yeah those makefiles can be a pain in the a**! I am currently working on one for devARM and am having a really great time :P
#145637 - Philip2 - Mon Nov 19, 2007 7:21 pm
I also tried the Makefile from the gba examples.
I set up the enviroment vars:
export DEVKITARM=/home/codeST/GBA/devkitARM
and set up a simple test C file in the same folder as the makefile.
When I run "make" then the only thing I get ist:
Code: |
make
linking multiboot
/home/codeST/GBA/devkitARM/bin/../lib/gcc/arm-eabi/4.1.2/../../../../arm-eabi/bin/ld: cannot find -lgba
collect2: ld returned 1 exit status
make[1]: *** [/home/codeST/FlunkyBall/FlunkyBall_mb.elf] Fehler 1
make: *** [build] Fehler 2
|
Why cant it find the gba lib? Do I need to modify the Makefile somehow?
I thought they would all be in the lib folder of devkitarm?
Thanks for your help
#145703 - anox - Tue Nov 20, 2007 7:08 pm
Hey Philip2, how about this one:
Code: |
fenriz@base666:~/Code/Java/Flunkyball$ make
arm-eabi-gcc -I./ -mthumb-interwork -mthumb -O2 -Wall -g -c main.cpp -o main.o
/home/fenriz/DevkitPro/devkitARM/bin/../lib/gcc/arm-eabi/4.1.2/../../../../arm-eabi/lib/thumb/libc.a(lib_a-abort.o): In function `abort':
(.text+0xc): undefined reference to `_exit'
/home/fenriz/DevkitPro/devkitARM/bin/../lib/gcc/arm-eabi/4.1.2/../../../../arm-eabi/lib/thumb/libc.a(lib_a-exit.o): In function `exit':
(.text+0x1a): undefined reference to `_exit'
/home/fenriz/DevkitPro/devkitARM/bin/../lib/gcc/arm-eabi/4.1.2/../../../../arm-eabi/lib/thumb/libc.a(lib_a-signal.o): In function `_raise_r':
(.text+0x110): undefined reference to `_getpid_r'
/home/fenriz/DevkitPro/devkitARM/bin/../lib/gcc/arm-eabi/4.1.2/../../../../arm-eabi/lib/thumb/libc.a(lib_a-signal.o): In function `_raise_r':
(.text+0x11a): undefined reference to `_kill_r'
/home/fenriz/DevkitPro/devkitARM/bin/../lib/gcc/arm-eabi/4.1.2/../../../../arm-eabi/lib/thumb/libc.a(lib_a-mallocr.o): In function `_malloc_r':
(.text+0x288): undefined reference to `_sbrk_r'
/home/fenriz/DevkitPro/devkitARM/bin/../lib/gcc/arm-eabi/4.1.2/../../../../arm-eabi/lib/thumb/libc.a(lib_a-mallocr.o): In function `_malloc_r':
(.text+0x3d4): undefined reference to `_sbrk_r'
/home/fenriz/DevkitPro/devkitARM/bin/../lib/gcc/arm-eabi/4.1.2/../../../../arm-eabi/lib/thumb/libc.a(lib_a-freer.o): In function `_malloc_trim_r':
(.text+0x2e): undefined reference to `_sbrk_r'
/home/fenriz/DevkitPro/devkitARM/bin/../lib/gcc/arm-eabi/4.1.2/../../../../arm-eabi/lib/thumb/libc.a(lib_a-freer.o): In function `_malloc_trim_r':
(.text+0x4e): undefined reference to `_sbrk_r'
/home/fenriz/DevkitPro/devkitARM/bin/../lib/gcc/arm-eabi/4.1.2/../../../../arm-eabi/lib/thumb/libc.a(lib_a-freer.o): In function `_malloc_trim_r':
(.text+0x76): undefined reference to `_sbrk_r'
collect2: ld returned 1 exit status
make: *** [Flunkyball.elf] Fehler 1
|
Paths are correctly set so I really dont know whats the matter. In case my makefile helps...
Code: |
#
# test.mak
#
# makefile for a simple demo
# --- Project details ---
PROJ := Flunkyball
EXT := gba
CFILES := main.cpp
COBJS := $(CFILES:.cpp=.o)
OBJS := $(COBJS)
#--- Tool settings ---
# for devkitARM r19+ use PREFIX := arm-eabi
PREFIX := arm-eabi-
AS := $(PREFIX)as
CC := $(PREFIX)gcc
LD := $(PREFIX)gcc
OBJCOPY := $(PREFIX)objcopy
MODEL := -mthumb-interwork -mthumb
#SPECS := -specs=gba.specs # comment out for DKA
ASFLAGS := -mthumb-interwork
CFLAGS := -I./ $(MODEL) -O2 -Wall
LDFLAGS := $(MODEL)
#--- Build steps ---
build : $(PROJ).$(EXT)
$(PROJ).$(EXT) : $(PROJ).elf
@$(OBJCOPY) -v -O binary $< $@
-@gbafix $@
$(PROJ).elf : $(OBJS)
@$(LD) $(OBJS) $(LDFLAGS) -o $@
$(COBJS) : %.o : %.cpp
$(CC) $(CFLAGS) -g -c $< -o $@
# --- Clean ---
.PHONY : clean
clean :
@rm -fv $(COBJS)
@rm -fv $(PROJ).$(EXT)
@rm -fv $(PROJ).elf
|
#145706 - wintermute - Tue Nov 20, 2007 7:35 pm
Couple of problems.
Code: |
#SPECS := -specs=gba.specs # comment out for DKA
|
Confusing comments and terminology here - the DKA in the comment actually refers to the obsolete devkitAdvance, not devkitARM. The specs line is required for devkitARM.
Since you're building C++ code you need to link with g++ and not gcc as specified here.
Personally I really recommend the devkitPro supplied templates, they automatically pick up source files, switch the linker as appropriate and auto generate dependencies during the build.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog
#145707 - wintermute - Tue Nov 20, 2007 7:38 pm
Philip2 wrote: |
When I run "make" then the only thing I get ist:
Code: |
make
linking multiboot
/home/codeST/GBA/devkitARM/bin/../lib/gcc/arm-eabi/4.1.2/../../../../arm-eabi/bin/ld: cannot find -lgba
collect2: ld returned 1 exit status
make[1]: *** [/home/codeST/FlunkyBall/FlunkyBall_mb.elf] Fehler 1
make: *** [build] Fehler 2
|
Why cant it find the gba lib? Do I need to modify the Makefile somehow?
I thought they would all be in the lib folder of devkitarm?
Thanks for your help |
libgba should be installed in the devkitPro folder containing the other libraries and toolchains.
See http://www.devkitpro.org/setup.shtml for details of the recommended layout.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog
#145712 - anox - Tue Nov 20, 2007 8:57 pm
Hey thanks a lot Wintermute. It worked.
I guess I will be analysing the whole lot the next couple of days to somewhat understand what happens there.
Cheers!
#145843 - anox - Fri Nov 23, 2007 6:41 pm
Now I only wonder why VisualBoyAdvance gives me a plain white screen when I tried to run the created .gba file...
#145859 - tepples - Sat Nov 24, 2007 12:18 am
If you compiled it with gba_mb.specs, does it work in VBA if you rename it from .gba to .mb? Does hello world (.../devkitPro/examples/gba/template) have the same problem? If so, this is a known bug in devkitARM R21's gba_mb linker script that I have told wintermute about.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#145879 - anox - Sat Nov 24, 2007 3:20 pm
Renamed it to .mb and it worked. Hmmm, haven't read this anywhere yet that you have to do that... Ow well, worked on painting stuff pixel by pixel all morning and its getting fun :P