#117692 - AdolescentFred - Tue Feb 06, 2007 6:21 pm
I'm new to gba development and I've been trying to get some simple code running using devkitARM and libgba, but anything that actually uses libgba.a (rather that just the headers) won't compile. I think it's not linking properly.
Here is my Makefile:
Code: |
PROJ= test
CC= arm-eabi-gcc
OBJCOPY= arm-eabi-objcopy
.PHONY : build
build:
$(CC) -mthumb-interwork -mthumb -I$(DEVKITPRO)/libgba/include -c $(PROJ).c
$(CC) -specs=gba.specs -mthumb-interwork -mthumb -L$(DEVKITPRO)/libgba/lib/ -lgba $(PROJ).o -o $(PROJ).elf
$(OBJCOPY) -v -O binary $(PROJ).elf $(PROJ).gba
-@gbafix $(PROJ).gba
.PHONY : clean
clean:
@rm -fv $(PROJ).o
@rm -fv $(PROJ).gba
@rm -fv $(PROJ).elf
|
Whenever i run make I get the same error from the second build line:
Code: |
test.o: In function `main':
test.c:(.text+0xae): undefined reference to `irqInit'
test.c:(.text+0xb8): undefined reference to `irqSet'
test.c:(.text+0xbe): undefined reference to `irqEnable'
collect2: ld returned 1 exit status
make: *** [build] Error 1
|
What am I missing? Anyone got any ideas?
#117694 - wintermute - Tue Feb 06, 2007 6:29 pm
#117698 - AdolescentFred - Tue Feb 06, 2007 6:50 pm
No thats not it. It manages the compile stage, and fails with that error when its linking (I think).
If I don't use and libgba funtions it compiles and runs fine using the same Makefile.
#117701 - wintermute - Tue Feb 06, 2007 7:17 pm
Ah, I see it, I've just had too many missing $(DEVKITPRO) variables today and went temporarily blind, sorry.
Change this line
Code: |
$(CC) -specs=gba.specs -mthumb-interwork -mthumb -L$(DEVKITPRO)/libgba/lib/ -lgba $(PROJ).o -o $(PROJ).elf
|
to this
Code: |
$(CC) -specs=gba.specs -mthumb-interwork -mthumb $(PROJ).o -L$(DEVKITPRO)/libgba/lib/ -lgba -o $(PROJ).elf
|
Libraries must be specified on the command line after any objects that reference them.
For what it's worth I always recommend using the devkitPro template projects where possible. While the makefiles are quite complex they're extremely flexible and let you get on with programming without worrying about make.
This particular makefile is little more than a script for a single source file project. Great for quick tests but not much cop for a larger project.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog
#117703 - AdolescentFred - Tue Feb 06, 2007 7:21 pm
Thanks that worked a treat. I'd rejected the devkitPro ones because of their complexity, and examples I'd downloaded hadn't compiled, I'll give them another go though.
Thanks
~Fred
#117739 - Massif - Wed Feb 07, 2007 1:34 am
I'm having a very similar problem with linking. I am using Eclipse as my IDE with the NDS Managedbuilder plugin. I've tried libnds-20060719 and libnds-20070127 so I don't think it's the version. I've also tried just doing the linking in a command prompt but got the same errors. Here is the (very basic) code I'm compiling:
Code: |
#include <stdio.h>
#include <nds.h>
#include <nds/arm9/console.h>
int main(int argcs, char* pArgs[]) {
powerON(POWER_ALL);
// Use the main screen for output
videoSetMode(MODE_0_2D | DISPLAY_BG0_ACTIVE);
vramSetBankA(VRAM_A_MAIN_BG);
BG0_CR = BG_MAP_BASE(31);
// Set the colour of the font to White.
BG_PALETTE[255] = RGB15(31,31,31);
consoleInitDefault((u16*)SCREEN_BASE_BLOCK(31), (u16*)CHAR_BASE_BLOCK(0), 16);
printf("\n\n\tHello World!\n");
}
|
and here is the console output:
Code: |
**** Build of configuration Release for project Test ****
make -k all
Building file: ../main.cpp
Invoking: GCC C++ Compiler
arm-eabi-g++ -I"C:\devkitPro\libnds\include" -O2 -g -Wall -c -fmessage-length=0 -ffast-math -fomit-frame-pointer -mthumb-interwork -mthumb -mcpu=arm9tdmi -mtune=arm9tdmi -DARM9 -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
Finished building: ../main.cpp
Invoking: GCC C++ Linker
arm-eabi-g++ ./main.o -mno-fpu -L"C:\devkitPro\libnds\lib" -Wl,-Map,arm9.elf.map -mthumb-interwork -specs=ds_arm9.specs -o"arm9.elf"
./main.o: In function `main':
C:\EclipseWorkspace\Test\Release/../main.cpp:10: undefined reference to `vramSetBankA'
C:\EclipseWorkspace\Test\Release/../main.cpp:14: undefined reference to `consoleInitDefault'
collect2: ld returned 1 exit status
make: *** [arm9.elf] Error 1
make: Target `all' not remade because of errors.
Build complete for project Test
|
I also tried to switch the options around to match the way you suggested above. It looks like this:
Code: |
arm-eabi-g++ -specs=ds_arm9.specs -mthumb-interwork -mthumb ./main.o -L"C:\devkitPro\libnds\lib" -Wl,-Map,arm9.elf.map -o"arm9.elf"
|
Any suggestions?
#117740 - wintermute - Wed Feb 07, 2007 1:51 am
Massif wrote: |
I also tried to switch the options around to match the way you suggested above. It looks like this:
Code: |
arm-eabi-g++ -specs=ds_arm9.specs -mthumb-interwork -mthumb ./main.o -L"C:\devkitPro\libnds\lib" -Wl,-Map,arm9.elf.map -o"arm9.elf"
|
Any suggestions? |
-lnds9
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog
#117742 - Massif - Wed Feb 07, 2007 1:58 am
Hooray, it works! Thank you!
I guess since the managedbuilder didn't include the libnds include and library paths by default, they also wouldn't put in the flags for them. Silly me.