gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Linking with Standard Library

#18 - Kater - Wed Jan 01, 2003 2:42 am

Greets All and Happy New Year,

Does anyone know whether it is possible to link with the standard C++ library when building GBA images using GCC? If so, can you point me in the right direction?

Thanks,
Kater

#34 - dovoto2 - Wed Jan 01, 2003 1:35 pm

$(PROJECT).elf : $(O_FILES)
$(CMPDIR)\ld $(LDFLAGS) -o $(PROJECT).elf $(O_FILES) -lstdc++ -lgcc -lc

thats how I do it. If you use devkit it should work fine. If you use Visual Studio for your IDE you can download the GBA appwizard from my site and it sets up a make file with full c++ suport... You will need to include the two .o files: crtbegin.o crtend.o as well as crt0.o. These are someware in your devkit install.
-dovoto

#54 - Kater - Thu Jan 02, 2003 12:58 am

Thanks for your suggestions dovoto2.

However, I'm using g++ to do the linking stage for me. I've since read that it automatically performs linking with c++ libraries. It seems to do so but now I'm getting strange errors.

I can successfully declare a std::string or std::vector in my code but as soon as I try to actually use it in my code the linker gives me these kind of errors:

/cygdrive/c/DevKitADV/bin/../lib/gcc-lib/arm-agb-elf/3.0.2/../../../../arm-agb-elf/lib/thumb/libstdc++.a(misc-inst.o):/home/Administrator/build-devkitadv/build-gcc/arm-agb-elf/thumb/libstdc++-v3/include/bits/stl_algobase.h:180: internal error: unsupported relocation error
/cygdrive/c/DevKitADV/bin/../lib/gcc-lib/arm-agb-elf/3.0.2/../../../../arm-agb-elf/lib/thumb/libstdc++.a(pure.o): In function `__cxa_pure_virtual':
../../../../../gcc-3.0.2/libstdc++-v3/libsupc++/pure.cc:49: undefined reference to `write'

Do you (or anyone) have any idea what this is all about?

Thanks heaps,
Kater

#55 - Legion - Thu Jan 02, 2003 1:09 am

Does the Visual Studio GBA appwizard work with VS .NET?

#898 - animension - Sat Jan 11, 2003 11:39 pm

Is there even support for STL other than strings? I thought maps and vectors and other high-level abstractions weren't implemented, though the headers are there (and thus the successful compile).

Also AFAIK, STL is extremely slow and should be avoided when programming for a limited platform like the GBA.

#1314 - mo - Thu Jan 16, 2003 6:11 pm

Hey Dovoto that appwizard is nice. I'm really having problems with step #9, however, do you have any advice?

Quote:

step 9:
Try not to be over awed by dovoto's superior intellect...This is the hardest step.


!-)

#1323 - maniac - Thu Jan 16, 2003 7:01 pm

I got the exact same problem as Kater (I also used g++). The STL string class works fine (however there seems to be some methods which aren't implemented?!).

vector<int> v; // works fine
v.push_back(1); // spawns the same error as Kater got

I tried my code using the appwizard with vc6 and the same problem occurs! So is animension correct about STL not being fully implemented?

#2043 - mo - Tue Jan 28, 2003 4:47 am

I was messing around with C++ today and saw something similar. I'm not using STL in the code, but have defined an abstract class with some pure virtual functions.

Code:

 F:\gba\devkitadv\bin\g++ -L F:\gba\devkitadv\lib\gcc-lib\arm-agb-elf\3.0.2\interwork -L F:\gba\devkitadv\arm-agb-elf\lib\interwork -L F:\gba\SGADE\lib -L F:\gba\devkitadv\lib/gcc-lib\arm-agb-elf\3.0.2\interwork -L F:\gba\devkitadv\arm-agb-elf\lib\interwork -T lnkscript -o kaboom.elf main.o Kaboom.o Sprite.o MadBomber.o -lsocrates -lg -lc -lgcc

/cygdrive/f/gba/devkitadv/bin/../lib/gcc-lib/arm-agb-elf/3.0.2/../../../../arm-agb-elf/bin/ld: Warning: /cygdrive/f/gba/devkitadv/bin/../lib/gcc-lib/arm-agb-elf/3.0.2/crtend.o does not support interworking, whereas kaboom.elf does

F:\gba\devkitadv\arm-agb-elf\lib\interwork/libstdc++.a(pure.o): In function `__cxa_pure_virtual':
../../../../../gcc-3.0.2/libstdc++-v3/libsupc++/pure.cc:49: undefined reference to `write'

#7989 - hnager - Mon Jun 30, 2003 3:31 am

I'm also having strange <vector> errors - I haven't tried including crtbegin.o crtend.o and crt0.o - is that the key? In short - I have a small file which traces out some text to the mappy console - if <vector> is included it doesn't work, without - it's fine.

#7994 - tepples - Mon Jun 30, 2003 4:50 am

You need the crt* files in order to set up support for C++ features.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#8030 - hnager - Tue Jul 01, 2003 1:03 am

I haven't been able to link the ctr files without getting multiple errors - example:

crt0.o: In function `__FarProcedure':
crt0.o(.text+0x1a8): undefined reference to `__sp_irq'

Here is my makefile - what is it that I am doing wrong?



PATH=c:\GBA\bin;
NAME = POLYGON

CFLAGS = -c -O3
MODEL = -mthumb -mthumb-interwork

$(NAME).bin : $(NAME).elf
objcopy -O binary $(NAME).elf $(NAME).bin

$(NAME).elf : main.o crt0.o crtbegin.o crtend.o
g++ $(MODEL) -nostartfiles -o $(NAME).elf main.o crt0.o crtbegin.o crtend.o

main.o : main.cpp
g++ $(CFLAGS) $(MODEL) main.cpp

crt0.o : crt0.s
g++ $(CFLAGS) $(MODEL) crt0.s