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.

Coding > Linker problem..

#20435 - dXtr - Tue May 11, 2004 12:37 pm

I do this (it's a little edit with newline for every command, so it's easier to read..):
c:\devkitadv-r5-beta-3/bin/arm-agb-elf-ld.exe -L c:\devkitadv-r5-beta-3/lib/gcc-lib/arm-agb-elf/3.2.2/interwork
-L c:\devkitadv-r5-beta-3/arm-agb-elf/lib/interwork
-L c:\devkitadv-r5-beta-3/arm-agb-elf/lib/krawall
--script c:\devkitadv-r5-beta-3/system/lnkscript-krawall
-o test.elf crt0.o main.o gbalib/Interrupt.o gbalib/Sprite.o gbalib/Video.o gbalib/Memory.o CGame.o ctgoblin.o samples.o
-lkrawall
-lm
-lstdc++
-lsupc++
-lgcc
-lc
-lgcc

and get this:
crt0.o: In function `__FarProcedure':
crt0.o(.text+0x214): undefined reference to `main'
crt0.o: In function `IntrRet':
crt0.o(.iwram+0x10c): undefined reference to `IntrTable'
make: *** [test.elf] Error 1

Anyone knows what's wrong? And if you need to se something that I've missed to post please say so and I post it to.

#20439 - NoMis - Tue May 11, 2004 1:53 pm

It seems you didnt have a main function. you need it for entry in you app

Code:

  int main()
  {
    ...
  }


also you seem to have enabled Interrupt support in the crt0.s
If so you need to define the IntrTable which later can contain the addresses of your different interrupt handlers.

NoMis

#20441 - dXtr - Tue May 11, 2004 1:58 pm

well... I do have a main:
Code:

// Start the game
int main(void)
{
    game = new CMyGame;
    game->Run();
        return(0);
}


and I do have a interrupt table to.
Code:

FuncInterrupt IntrTable[] =
{
    VBLANK,
    HBLANK,
    VCOUNT,
    TIMER0,
    TIMER1,
    TIMER2,
    TIMER3,
    COM,
    DMA0,
    DMA1,
    DMA2,
    DMA3,
    BUTTON,
    CART
};

#20442 - Nikkoz - Tue May 11, 2004 2:04 pm

Do you by any chanse use a Pascal compiler? Those compiles dosen't handle C++ very well...

#20443 - dXtr - Tue May 11, 2004 2:31 pm

And by the way.. the exact same coded works under ham with out this linking error

#20525 - dXtr - Wed May 12, 2004 2:38 pm

hm... is there none who could help me.. cuz I haven't managed to fix the problem yet. =(

#20538 - sajiimori - Wed May 12, 2004 7:07 pm

Maybe it'll take some work on your part. Try compiling smaller apps, with and without krawall, using ld directly to link and using g++ or gcc as a front end, etc.

I bet you could narrow the problem down to something very specific, with some effort.

#20589 - isildur - Thu May 13, 2004 2:26 pm

I once had a similar problem and it was because I was linking with the wrong crt0.o. Some use AgbMain() and others use main()... It might not be using the linkscript and the crt0 you think...

#20622 - dXtr - Thu May 13, 2004 8:19 pm

isildur wrote:
I once had a similar problem and it was because I was linking with the wrong crt0.o. Some use AgbMain() and others use main()... It might not be using the linkscript and the crt0 you think...


yeah I've been thinking of that too. So I'm considering remove all other crt0.o files I can find on my computer and try again.

#20661 - dXtr - Fri May 14, 2004 3:06 pm

guess what.. it wasn't a linking error.. it was a compile error but it didn't show up until I link. cuz I compared the .o file I got from devkitadv. and the one I got from ham and I discoverd that they had different size with ~200byte. I checked the generated .s files and found out that they don't look the same. So I guess I've missed some flag or something >_<

here is some from the start of devkits .s file:
Code:


   .global   IntrTable
   .data
   .align   2
   .type   IntrTable,object
   .size   IntrTable,56
IntrTable:
   .word   0
   .word   0
   .word   0
   .word   0
   .word   0
   .word   0
   .word   0
   .word   0
   .word   0
   .word   0
   .word   0
   .word   0
   .word   0
   .word   0
   .text
   .align   2
   .global   main
   .type   main,function
main:


and here is some from the start of ham .s file:
Code:

   .global   IntrTable
   .bss
   .global   IntrTable
   .align   2
   .type   IntrTable, %object
   .size   IntrTable, 56
IntrTable:
   .space   56
   .text
   .align   2
   .global   main
   .type   main, %function
main:



anyone that can point out what I've made wrong?

#20672 - dXtr - Fri May 14, 2004 4:56 pm

man.. this is strange. I've been using the devkit adv. release 5 (beta3)
until now. Then I just had this idea.. and downloaded release 4... and guess what? now my code compiles AND links AND works! ^_^
but why? is there something wrong with release 5?