undefined reference to `main'

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
mase
Posts: 23
Joined: Fri Aug 21, 2009 3:04 am

undefined reference to `main'

Post by mase »

Hello!
What does this error mean? How can I solve this? It appears, when
compiling openttd.

Code: Select all

/usr/share/psp-dev/bin/../lib/gcc/psp/4.3.2/../../../../psp/lib/crt0.o: In function `_main':
/tmp/psptoolchain/build/pspsdk/src/startup/crt0.c:86: undefined reference to `main'
collect2: ld returned 1 exit status
May the force be with us!
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

Post by jojojoris »

It means the linker can't find any main function.

Code: Select all

int main(){
     SetupCallbacks();
     makeNiceGame();
     sceKernelExitGame();
}
mase
Posts: 23
Joined: Fri Aug 21, 2009 3:04 am

Post by mase »

The only main function is

Code: Select all

int ttd_main(int argc, char *argv[])
in openttd.cpp.
Even if I rename ttd_main to main, I get the same error.
But it compiles fine for Linux.
But it is an SDL application. So if I link SDLmain, it should work, but
it doesn't.
May the force be with us!
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

Post by jojojoris »

mase wrote:The only main function is

Code: Select all

int ttd_main(int argc, char *argv[])
in openttd.cpp.
Even if I rename ttd_main to main, I get the same error.
But it compiles fine for Linux.
But it is an SDL application. So if I link SDLmain, it should work, but
it doesn't.
Don't use SDL. It's verry slow. Try oslib as graphics engine.

Code: Select all

int main(){
     SetupCallbacks();
     makeNiceGame();
     sceKernelExitGame();
}
mase
Posts: 23
Joined: Fri Aug 21, 2009 3:04 am

Post by mase »

I must use SDL, because it is not my code.
I added -l SDLmain -lSDL in build.mak of the SDK. Now I get

Code: Select all

psp-gcc -I. -I/usr/share/psp-dev/psp/sdk/include  -D_PSP_FW_VERSION=150  -L. -L/usr/share/psp-dev/psp/sdk/lib    -lSDLmain -lSDL  -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o .elf
/usr/share/psp-dev/bin/../lib/gcc/psp/4.3.2/../../../../psp/lib/libSDLmain.a(SDL_psp_main.o): In function `main':
psp/SDL_psp_main.c:86: undefined reference to `SDL_main'
collect2: ld returned 1 exit status
May the force be with us!
sauron_le_noir
Posts: 203
Joined: Sat Jul 05, 2008 8:03 am

Post by sauron_le_noir »

if you use SDL_MAIN it declare for you a main() function but within this function
a call has been made to sdl_main(int argc,char **argv) to init you SDL program
so it is normal that you've got a undefined reference to `SDL_main'n if you don't provide a sdl_main function



int main(int argc, char *argv[])
{
pspDebugScreenInit();
sdl_psp_setup_callbacks();

/* Register sceKernelExitGame() to be called when we exit */
atexit(sceKernelExitGame);

(void)SDL_main(argc, argv);
return 0;
}
mase
Posts: 23
Joined: Fri Aug 21, 2009 3:04 am

Post by mase »

The code does not provide such a function. But the code, that compiles,
doesn't, too.
Maybe you could have a look on it.
The one I am working on is here:
http://www.openttd.org/en/
It is the version 0.7.2, which I configured

Code: Select all

./configure --os=psp --host=psp --with-sdl=/usr/share/psp-dev/psp/bin/sdl-config --with-allegro=/usr/share/psp-dev/psp/bin/psp-allegro-config --with-freetype=/usr/share/psp-dev/psp/bin/freetype-config
The working one is here:
http://sourceforge.net/projects/openttd-psp
It is the version 0.5.3, which compiles and runs fine.
But as I said, both don't provide such a function.
May the force be with us!
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

if you're using -lSDLmain
the you need to define SDL_main and use that as your main function
mase
Posts: 23
Joined: Fri Aug 21, 2009 3:04 am

Post by mase »

Yes, but the working code doesn't provide a SDL_main function, too.
So how can it run?
May the force be with us!
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

mase wrote:Yes, but the working code doesn't provide a SDL_main function, too.
So how can it run?
Buried in the makefile(s) somewhere is probably a define for SDL_main that sets it to ttd_main.
mase
Posts: 23
Joined: Fri Aug 21, 2009 3:04 am

Post by mase »

No, there isn't. Please check the code, if you don't believe me.
May the force be with us!
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Okay, main() is in the platform specific code like os2.cpp. In os2.cpp you find:

Code: Select all

int CDECL main(int argc, char *argv[])
{
	SetRandomSeed(time(NULL));

	return ttd_main(argc, argv);
}
Clearly, in your psp.cpp (or whatever you call the PSP platform specific file you made), you need the same thing.
Post Reply