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 problem with DevKitAdv

#13259 - MumblyJoe - Wed Dec 10, 2003 2:10 am

OK, I am trying to link in some music to a game I am writing, but I am having trouble.

I have a:
.cpp file that has a long array of data - the music.
.h file that has an extern declaration of that array.
.cpp file which is the game and includes the above .h file.

I compiled the .cpp file with the music in it using g++, no errors.
I compile the game with g++ .cpp file, no errors.
I link the two together with g++, and the array cannot be found.

I have tried using extern "C" for both to stop name mangling, and the nm tool which comes with devkitadv says that 'heyladies' (my array name) is the name in the music .o file, and says that my game .o file has an extern variable of the same name, but somehow the linker is freaking out and not doing what I want.

My .bat file for compiling the music is this:
Code:
g++ -c -nostartfiles -mthumb -mthumb-interwork -fno-rtti -fno-exceptions -o heyladies.o heyladies.c


My .bat file for compiling my game and linking the two is this:
Code:
g++ -c -O3 -mthumb -mthumb-interwork -fno-rtti -fno-exceptions -o Frogger.o Frogger.cpp
g++ -mthumb -mthumb-interwork -o Frogger.elf heyladies.o Frogger.o
objcopy -O binary Frogger.elf Frogger.gba


I have tried re-ordering the files in the linking line, that didnt help either. Oh and I know .bat files are a nasty way of doing things and I should use makefiles but I like this way.

Just including the array of music into my game instead of compiling it seperately and linking them is out of the question, as it is the whole of Hey Ladies by The Beastie Boys, and the music file takes over 30 minutes to compile on the piece of shit computer I use for GBA development, while compiling it seperately once (and sleeping while it does it) then compiling the game and linking them takes like 15 seconds each time i make a change.

Heres the error I get:
Code:
C:\Programming\GBA Projects\TileFrogger>g++ -c -O3 -mthumb -mthumb-interwork -fno-rtti -fno-exceptions -o Frogger.o Frogger.cpp

C:\Programming\GBA Projects\TileFrogger>g++ -mthumb -mthumb-interwork -o Frogger.elf heyladies.o Frogger.o
Frogger.o: In function `Frogger::Start()':
Frogger.o(.gnu.linkonce.t._ZN7Frogger5StartEv+0xe4): undefined reference to `heyladies'
collect2: ld returned 1 exit status

C:\Programming\GBA Projects\TileFrogger>objcopy -O binary Frogger.elf Frogger.gba
objcopy: Frogger.elf: No such file or directory

Tool completed with exit code 1

Any ideas folks?
_________________
www.hungrydeveloper.com
Version 2.0 now up - guaranteed at least 100% more pleasing!

#13260 - MumblyJoe - Wed Dec 10, 2003 2:22 am

I just had a moment of realisation, and put a function that returned a pointer to the array in the music .cpp file, and declared that extern in the header, and used that function instead, and it links fine now! I still have to see if it worked properly but hooray anyway!

Any ideas why this happened?
_________________
www.hungrydeveloper.com
Version 2.0 now up - guaranteed at least 100% more pleasing!

#13304 - evil saltine - Wed Dec 10, 2003 10:19 pm

If you use a .cpp file for the music instead of .c it should work fine, I had the same problem. I don't know why it does that.