#39433 - AssHead - Fri Apr 08, 2005 9:33 pm
I've been spoiled by MSVC++, so I'm not very good with command line compilers. I'm writing a GBA game using Devkit Advance. I need to switch my project from C to C++ so I can take advantage of C++'s OOP features. I switched my compiler to g++, but I got an error about missing libstdc++.a. I redownloaded Devkit and found the file, but now I'm getting new linking errors.
Code: |
g++ -c -O2 src/entity/entity.cpp
g++ -c -O2 src/entity/entity_player.cpp
g++ -c -O2 src/main.cpp
g++ -c -O2 src/bg.cpp
g++ -c -O2 src/gba.cpp
g++ -o rom.elf entity.o entity_player.o main.o bg.o gba.o
/cygdrive/c/devkitadv/bin/../lib/gcc-lib/arm-agb-elf/3.0.2/../../../libstdc++.a(
pure.o): In function `__cxa_pure_virtual':
pure.o(.text+0x18): undefined reference to `write'
/cygdrive/c/devkitadv/bin/../lib/gcc-lib/arm-agb-elf/3.0.2/../../../libstdc++.a(
eh_throw.o): In function `__cxa_rethrow':
eh_throw.o(.text+0x114): undefined reference to `_Unwind_SjLj_Resume_or_Rethrow'
|
I done some searching on Google, and found something about these symbols being defined in libgcc_s.so.1. I have no clue what kind of file this is, and I can't seem to find it anywhere. It didn't come with Devkit Advance. Can anyone help me out?
Thanks. :)
#39448 - tepples - Fri Apr 08, 2005 11:45 pm
You get the "undefined reference to write" error because the default implementation of a pure virtual function will try to write() an error message to the screen, but the GBA has no standard implementation of character I/O. Therefore, you'll need to implement write(). If you are using AGBTTY or another terminal emulator as your text backend, it should look something like this:
Code: |
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <errno.h>
#include "agbtty.h"
ssize_t write(int d, const void *buf, size_t nbytes)
{
if(d == 1 || d == 2) /* file descriptors for stdout or stderr */
{
return agbtty_write(const void *buf, size_t nbytes);
}
else
{
errno = EBADF;
return -1;
}
} |
Otherwise, just tell it to ignore the write using a stub implementation:
Code: |
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
ssize_t write(int d, const void *buf, size_t nbytes)
{
return nbytes;
} |
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#39459 - AssHead - Sat Apr 09, 2005 4:19 am
Thanks! That took care of the write() problem, but I still get the "undefined reference to `_Unwind_SjLj_Resume_or_Rethrow'" error.
Code: |
g++ -c -O2 src/main.cpp
g++ -c -O2 src/bg.cpp
g++ -c -O2 src/gba.cpp
g++ -c -O2 src/entity/entity.cpp
g++ -c -O2 src/entity/entity_player.cpp
g++ -o rom.elf main.o bg.o gba.o entity.o entity_player.o
/cygdrive/c/devkitadv/bin/../lib/gcc-lib/arm-agb-elf/3.0.2/../../../libstdc++.a(
eh_throw.o): In function `__cxa_rethrow':
eh_throw.o(.text+0x114): undefined reference to `_Unwind_SjLj_Resume_or_Rethrow' |
[EDIT] Nevermind. I'm just going to switch back to C. I guess I'll just have to redesign my entity system.
#39508 - Quirky - Sat Apr 09, 2005 8:36 pm
You might need some -mthumb-interworking flags on the link step perhaps? Which version of Devkit Advance are you using? I vaguely remember C++ not being well tested in a couple of releases, though I may be wrong. Have you tried switching to Devkit ARM?
#39513 - AssHead - Sat Apr 09, 2005 9:37 pm
I hope I can get this working. I'm going nuts trying to design a game engine that doesn't rely on inheritance.
I tried the -mthumb-interwork flag. I got couple hundred errors about "blah.o doesn't support interworking, whereas blah.o does." It didn't fix the '_Unwind_SjLj_Resume_or_Rethrow' error.
I downloaded Devkit way back in October of 03 and its been collecting dust on my hard drive since then. I can't seem to find a version number anywhere so I'm not sure exactly which release I'm using. I'm going to switch to Devkit ARM later and see if that does it.
[EDIT] Ok, I've switched over to DevKitArm. It compiles fine now, but the rom won't run! I just get a blank white screen. Did I set up DevKit wrong? Or am I not compiling something right? Sorry to ask so many questions, but I really don't know much about GCC and I'm pretty much in the dark about what to try next. Heres my makefile.
Code: |
CC = arm-elf-g++
CFLAGS = -c
LIST = main.o bg.o gba.o
ENT_LIST = entity.o entity_player.o
all: rom.gba
rom.gba: rom.elf
arm-elf-objcopy -O binary rom.elf rom.gba
gbafix rom.gba -tMYROM -cMYRM -mMM -r1
rom.elf: $(LIST) $(ENT_LIST)
$(CC) -o rom.elf $(LIST) $(ENT_LIST)
$(ENT_LIST): %.o: src/entity/%.cpp
$(CC) $(CFLAGS) $<
$(LIST): %.o: src/%.cpp
$(CC) $(CFLAGS) $<
|
Last edited by AssHead on Sun Apr 10, 2005 12:04 am; edited 1 time in total
#39521 - tepples - Sat Apr 09, 2005 11:54 pm
Have you tried to compile C++ with inheritance but without exceptions?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#39522 - AssHead - Sun Apr 10, 2005 12:07 am
I edited my above reply around the same time you posted, tepples. Switching to DevKitArm worked, but now I've got a new problem.
#39523 - tepples - Sun Apr 10, 2005 12:25 am
With devkitARM, you have to add -specs=gba.specs or -specs=gba_mb.specs (depending on whether it's a ROM or a multiboot) somewhere on the linker command line (the one with -o something.elf). Otherwise, it seems to default to a build for some platform other than Game Boy Advance.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#39529 - AssHead - Sun Apr 10, 2005 12:58 am
I added that line, but the emulator still gives me a plain white screen. Am I missing anything else?
Code: |
CC = arm-elf-g++
CFLAGS = -c -O2 -Wall
LIST = main.o bg.o gba.o
ENT_LIST = entity.o entity_player.o
all: rom.gba
rom.gba: rom.elf
arm-elf-objcopy -O binary rom.elf rom.gba
gbafix rom.gba -tMYROM -cMYRM -mMM -r1
rom.elf: $(LIST) $(ENT_LIST)
$(CC) -specs=gba.specs -o rom.elf $(LIST) $(ENT_LIST)
$(ENT_LIST): %.o: src/entity/%.cpp
$(CC) $(CFLAGS) $<
$(LIST): %.o: src/%.cpp
$(CC) $(CFLAGS) $<
|
#39531 - tepples - Sun Apr 10, 2005 1:16 am
Make sure to use -mthumb-interwork on every line that calls $(CC), and make sure to use -mthumb when compiling C source code (other than code that you intend to put in IWRAM) and when linking.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#39532 - AssHead - Sun Apr 10, 2005 1:31 am
THAT DID IT! It works perfectly now. I tried putting -mthumb-interwork in before, but I forgot to add it to the linking stage and I got a bunch of errors. Thanks for all your help. I can finally move onto finishing my entity system. :)