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.

ASM > crt0 ignoring main()

#2613 - Vivi - Sun Feb 09, 2003 2:15 am

I'm sorry if this sounds like an idiotic question, but I'm far more used to programming in C than ASM.

crt0.s is included in my project. Every time I attempt to compile the game, though, it says 'IntrRet': Undefined reference to main. I don't know why it isn't linking to Main, because under any other code it works fine. Main is called main(), not AgbMain(), so I know it's not that...

What problem does that indicate?

#2614 - MayFly - Sun Feb 09, 2003 5:30 am

Hi Vivi,

If you are using Jeff's Crt0.s (version 1.28 at least) did you uncomment out the ".equ _CPPSupport, 1" statement?

@ Uncomment the following line to support C++ development.
@ You also need to name your main C function the following:
@ int main (void) ...instead of... int AgbMain (void)
@ Doing so will cause ~5500 bytes of c++ support code to be
@ linked in with your project so do not enable c++ support
@ unless you plan to use it.

@ .equ __CPPSupport, 1

As I understand it, if you're compiling any C++ code you have to modify the Crt0.s file as such. Don't forget the main function must be declared as a function returning type int.

Hope this helps.

MayFly

#2618 - siaspete - Sun Feb 09, 2003 11:09 am

If you're using Devkit Advance you don't need a crt0.s. The compiler will supply one internally. To save some headaches, make sure you link your program using gcc (or g++) instead of ld.

#2626 - Vivi - Sun Feb 09, 2003 5:08 pm

Well, it turns out though, the makefile was compiling incorrectly. I solved the problem by replacing it with a new one. But thanks anyways!

#2635 - Maddox - Sun Feb 09, 2003 7:16 pm

siaspete,
What types of headaches does ld give that gcc doesn't? How do you do the actual link with gcc?
_________________
You probably suck. I hope you're is not a game programmer.

#5871 - Jason Wilkins - Sun May 11, 2003 10:18 am

ld is a pain because to link a C program correctly you need to supply five files in addition to any which are in your project. It is doubly painful because of multilib (arm, thumb, arm-thumb-interwork, thumb-thumb-interwork). Also, there are several support libraries that have to be supplied just right.

Here is how gcc calls ld:

ld -o mygame.elf crt0.o crtn.o crtbegin.o myfile1.o myfile2.o crtend.o crti.o -lgcc -lc -lgcc -lmylib1 -lmylib2

gcc will do this for you if you just call it as:

gcc -o mygame.elf mygame.o -lmylib1 -lmylib2

Use g++ for c++ programs, it will add -lstdc++ and -lsupc++ to the command line as well.

You may think that does not look too bad, but now consider multilib. The crt*.o files have to come out of the correct lib directory lib, lib/thumb, lib/interwork, or lib/thumb/interwork. Providing the full path for each will make the command line quite long! I'm not even sure how to get the -l option to get the libraries out of the correct multilib directories. I have never tried it because I always use gcc or g++ to figure it all out for me.

Even a program with no C or C++ support can benefit by using the -nostartfiles and/or -nostdlib options with gcc, because gcc can still be used to link with the correct version of a library.

DevKit Advance R5 provides environment variables to make finding crt0.o easier. The variables CRT0, CRT0_THUMB, CRT0_INTERWORK, and CRT0_THUMB_INTERWORK are set to the location of the crt0.o

You can use this with gcc to link a program that does not use main, and would have no constructor, destructor, or atexit support.

gcc -o mygame.elf -nostartfiles -nostdlib $CRT0 myfile1.o myfile1.o -lsomelib
_________________
http://devkitadv.sourceforge.net