#28109 - mr_square - Tue Oct 26, 2004 11:22 pm
Hi all - I'm having some problems getting my program to use AAS with my Windows C++ project. I've followed the instructions in the file, but it doesn't seem to want to work...
I've put the AAS library in a LibAAS folder. My main program #includes AAS.h. I've put the 'extern "C" void InterruptProcess()' in my main.cpp file for now. My make bat file looks like this:
Code: |
path=C:\devkitadv\bin
g++ -o main.elf -LLibAAS -ILibAAS -lAAS city.o citybackdrop.o defines.cpp crt0.s main.cpp testroom.cpp room.cpp ball.cpp collisionDetector.cpp DMA.cpp fallState.cpp drawState.cpp background.cpp idleState.cpp jumpState.cpp lookUpState.cpp swipeState.cpp runLeftState.cpp trig.cpp kneelState.cpp runRightState.cpp playerState.cpp -lm -LLibAAS -ILibAAS -l AAS
objcopy -O binary main.elf main.bin
|
But I get loads of warnings about multiple definitions, something not supporting interworking 'but main.elf does', and a load of undefined references. Help!
Also - whats 'crt0.s'? Is it important? I thought it was so just included it with the rest of my source code - is that right?
#28111 - Abscissa - Tue Oct 26, 2004 11:44 pm
Unless I misunderstand you, it sounds like you're trying to use AAS for a Windows program instead of a GBA program? I don't think AAS works for anything other than GBA.
#28112 - mr_square - Tue Oct 26, 2004 11:50 pm
lol - no, its definately a GBA game :p
Sorry, I just called it a 'Windows C++ Project' in case the setup depended on the language/OS. I have it all compiling and running fine, and am now trying to get a sound system working.
#28117 - jd - Wed Oct 27, 2004 12:20 am
mr_square wrote: |
Code: |
path=C:\devkitadv\bin
g++ -o main.elf -LLibAAS -ILibAAS -lAAS city.o citybackdrop.o defines.cpp crt0.s main.cpp testroom.cpp room.cpp ball.cpp collisionDetector.cpp DMA.cpp fallState.cpp drawState.cpp background.cpp idleState.cpp jumpState.cpp lookUpState.cpp swipeState.cpp runLeftState.cpp trig.cpp kneelState.cpp runRightState.cpp playerState.cpp -lm -LLibAAS -ILibAAS -l AAS
objcopy -O binary main.elf main.bin
|
|
You seem to be mixing the compile stage with the link stage. Ideally, you should compile each of the .cpp files to .o files and then link them. "-ILibAAS" should be included at the compile stage, and "-LLibAAS -lAAS" should be included at the link stage.
It would be easiest if you just used a makefile instead, as they're specifically designed for this sort of thing and then you can just modify the example ones than come with AAS to compile your code. They're very easy to use (to compile AASExample just launch the devkit's shell, cd to the appropriate folder and type "make").
However, I've hacked together the batch file below to compile AASExample which you might be able to use as a basis for your own project, but I'd still recommend switching to proper makefiles as it's easier in the long run:
Code: |
path=c:\devkitadv-r5-beta-3\bin
conv2aas AAS_Data
arm-agb-elf-as -mthumb-interwork -o AAS_Data.o AAS_Data.s
arm-agb-elf-gcc -mthumb -O3 -ffixed-r14 -funroll-loops -ILibAAS -mthumb-interwork -fomit-frame-pointer -mapcs-32 -mcpu=arm7tdmi -ffast-math -fno-exceptions -fno-rtti -c AASExample.c -o AASExample.o
arm-agb-elf-gcc -mthumb-interwork -Xlinker -Map map.out -nostartfiles -Tlnkscript -o AASExample.tmp crt0.o AAS_Data.o AASExample.o -LLibAAS -lAAS
objcopy -O binary AASExample.tmp AASExample.gba
|
The file above is set up for devkitadv-r5-beta-3 so you might need to make some changes depending on what devkit you're using.
mr_square wrote: |
But I get loads of warnings about multiple definitions, something not supporting interworking 'but main.elf does', and a load of undefined references. Help!
|
If you've reworked it using the batch file above and you still get errors, it would be useful to know precisely which ones you're getting.
mr_square wrote: |
Also - whats 'crt0.s'? Is it important? I thought it was so just included it with the rest of my source code - is that right? |
crt0.s contains the startup code for the GBA. It initialises the static/global variables and things like that before your code is called. Most devkits come with one built-in - you can use those if you prefer, although if you're planning to use lots of interrupts you'll need to use the one that comes with AAS (or something equivalent) to give Timer 1 interrupts priority.
#28118 - mr_square - Wed Oct 27, 2004 12:28 am
fantastic - thankyou :) I'll give that a try now.
Yeah, I think I'm definately going to make the switch to a proper makefile - my method has given me nothing but headaches recently.
#28120 - jd - Wed Oct 27, 2004 12:52 am
mr_square wrote: |
Yeah, I think I'm definately going to make the switch to a proper makefile - my method has given me nothing but headaches recently. |
Great, I'm glad to hear it (the switch, not the headaches :). By the way, given that you're making a C++ project, it would probably be best to base your makefile on the one for AASExample_C++ (rather than AASExample, as I implied above).
#28123 - mr_square - Wed Oct 27, 2004 1:35 am
right - I can run makefiles quite happily now, but still having a few problems. Firstly, trying to run the makefile on the AAS C++ example produces an error right at the end saying:
Code: |
process_begin: CreateProcess(null), gbafix AASExample.gba, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [AASExample.gba] Error 2
|
It looks like its creating the .tmp file but not converting it to .gba. Its not a massive problem, as I can just rename .tmp to .elf and its fine, but any ideas why?
I tried modifying the makefile for my own code - I take it all I really need to alter is the files in the line:
Code: |
# Files you want to go in ROM (AAS_Data.o must go first)
SRC = AAS_Data.o AASExample.o
|
right? I just whacked in a list of all the .cpp files that my compiler was using before in my .bat file, but its first complaint was that it can't find the AAS.h file. Its in a folder called 'LibAAS' just as before, and I havent touched any of the other options. If I just copy it over to the source directory, I start getting a load of undefined reference errors - it looks like the make file isn't seeing the LibAAS directory properly.[/code]
#28136 - jd - Wed Oct 27, 2004 5:37 am
mr_square wrote: |
Code: |
process_begin: CreateProcess(null), gbafix AASExample.gba, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [AASExample.gba] Error 2
|
|
"gbafix" is a utility that corrects the checksum in the file. This checksum is checked by the GBA when it runs the program - if it doesn't match then the GBA won't run the ROM. However, emulators don't check it and all the 3rd party linkers that I'm aware of automatically correct the checksum when they transfer the file, but if you're planning to send your software to a publisher then it would be a good idea to use it.
To fix the problem you can either download gbafix from the "Header Tools" section of gbadev.org..
http://www.gbadev.org/tools.php?section=hea
(you should download "GBA ROM Fixer 1.03" and then make sure it's in your path)
..or you could just remove the last line ("gbafix $@") from the makefile.
mr_square wrote: |
I just whacked in a list of all the .cpp files that my compiler was using before in my .bat file,
|
Note that you need to put the names of the object files you want to make, rather than the source files - it will work out which source files to use automatically using the rules that are given later in the file. I guess it would look something like:
Code: |
SRC = AAS_Data.o city.o citybackdrop.o defines.o main.o testroom.o room.o ball.o collisionDetector.o DMA.o fallState.o drawState.o background.o idleState.o jumpState.o lookUpState.o swipeState.o runLeftState.o trig.o kneelState.o runRightState.o playerState.o
|
#28152 - mr_square - Wed Oct 27, 2004 2:50 pm
I'm getting there, slowly but surely!
It now compiles (mostly), but I'm getting some errors:
Code: |
main.o : undefined reference to 'operator new(unsigned long)' |
and the same for another class that uses 'new'
#28183 - jd - Wed Oct 27, 2004 6:13 pm
mr_square wrote: |
I'm getting there, slowly but surely!
It now compiles (mostly), but I'm getting some errors:
Code: | main.o : undefined reference to 'operator new(unsigned long)' |
and the same for another class that uses 'new' |
You might need to change the line that reads..
..to..
If that doesn't work, then it would be useful to know which file "new" is being used in and how it was being compiled before.
#28188 - mr_square - Wed Oct 27, 2004 6:44 pm
Hmm - thats got rid of the 'new' problem. But a couple more have surfaced:
Code: |
c:\devkitadv\bin\..\lib\gcc-lib\arm-agb-elf\3.2.2\..\..\..\..\arm-agb-efl\lib\interwork\libc.a(agb-sbrk.o): In function 'AgbMain':
../../../../../../../gcc-3.2.2./newlib/libc/sys/agb/agbmain/agbmain.c:24: undfined reference to '_init'
../../../../../../../gcc-3.2.2./newlib/libc/sys/agb/agbmain/agbmain.c:24: undfined reference to '_fini'
|
and undefined references to '__appended_end', '__heap_limit' and '__appended_start' in function '_sbrk'
There is also a line saying that section .ewram overlaps section .cartrom.data.
#28192 - jd - Wed Oct 27, 2004 7:08 pm
mr_square wrote: |
Code: |
c:\devkitadv\bin\..\lib\gcc-lib\arm-agb-elf\3.2.2\..\..\..\..\arm-agb-efl\lib\interwork\libc.a(agb-sbrk.o): In function 'AgbMain':
../../../../../../../gcc-3.2.2./newlib/libc/sys/agb/agbmain/agbmain.c:24: undfined reference to '_init'
../../../../../../../gcc-3.2.2./newlib/libc/sys/agb/agbmain/agbmain.c:24: undfined reference to '_fini'
|
|
I'd guess you need to change your code's entry function name from "int main(void)" to "int AgbMain(void)".
EDIT: Since you're using C++ you'll also need to disable name mangling by including "extern "C"" - i.e.:
Code: |
extern "C" int AgbMain(void)
|
#28215 - mr_square - Wed Oct 27, 2004 9:16 pm
Thanks jd - you've been so helpful - I feel a bit guilty asking so many questions! :p
This *hopefully* is the last problem - I'm still getting these last few undefined references:
Code: |
c:\devkitadv\bin\..\lib\gcc-lib\arm-agb-elf\3.2.2\..\..\..\..\arm-agb-efl\lib\interwork\libc.a(agb-sbrk.o): In function '_sbrk':
../../../../../../../gcc-3.2.2./newlib/libc/sys/agb/agbmain/agbmain.c:24: undefined reference to '_appended_end'
../../../../../../../gcc-3.2.2./newlib/libc/sys/agb/agbmain/agbmain.c:24: undfeined reference to '_heap_limit'
../../../../../../../gcc-3.2.2./newlib/libc/sys/agb/agbmain/agbmain.c:24: undefined reference to '_appended_start'
|
edit* I've just found a topic from a guy with the same problem - jd, you suggested that a new lnkscript might sort out the problem - did it work?
http://forum.gbadev.org/viewtopic.php?t=2131&highlight=sbrk
#28223 - jd - Thu Oct 28, 2004 12:29 am
mr_square wrote: |
edit* I've just found a topic from a guy with the same problem - jd, you suggested that a new lnkscript might sort out the problem - did it work?
|
Yes, it did. Which lnkscript are you using at the moment - the one that's in the AASExample_c++ folder or a different one? (The makefile is set to use the one in the project's folder.)
If you've tried the AASExample_c++ one and you still get the same problem then email or PM me and I'll send you the lnkscript.
#28224 - mr_square - Thu Oct 28, 2004 12:34 am
pm'd
#28243 - mr_square - Thu Oct 28, 2004 10:56 am
right all sorted now - that linker script sorted it out eventually, in case anyone wanted to know.
Many thanks to jd.