forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

undefined reference to `main'

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
mase



Joined: 21 Aug 2009
Posts: 23

PostPosted: Mon Aug 24, 2009 12:23 am    Post subject: undefined reference to `main' Reply with quote

Hello!
What does this error mean? How can I solve this? It appears, when
compiling openttd.
Code:
/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!
Back to top
View user's profile Send private message
jojojoris



Joined: 30 Mar 2008
Posts: 261

PostPosted: Mon Aug 24, 2009 1:07 am    Post subject: Reply with quote

It means the linker can't find any main function.
_________________
Code:
int main(){
     SetupCallbacks();
     makeNiceGame();
     sceKernelExitGame();
}
Back to top
View user's profile Send private message
mase



Joined: 21 Aug 2009
Posts: 23

PostPosted: Mon Aug 24, 2009 1:35 am    Post subject: Reply with quote

The only main function is
Code:
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!
Back to top
View user's profile Send private message
jojojoris



Joined: 30 Mar 2008
Posts: 261

PostPosted: Mon Aug 24, 2009 3:30 am    Post subject: Reply with quote

mase wrote:
The only main function is
Code:
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:
int main(){
     SetupCallbacks();
     makeNiceGame();
     sceKernelExitGame();
}
Back to top
View user's profile Send private message
mase



Joined: 21 Aug 2009
Posts: 23

PostPosted: Mon Aug 24, 2009 4:04 am    Post subject: Reply with quote

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:
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!
Back to top
View user's profile Send private message
sauron_le_noir



Joined: 05 Jul 2008
Posts: 229

PostPosted: Mon Aug 24, 2009 4:19 am    Post subject: Reply with quote

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;
}
Back to top
View user's profile Send private message Send e-mail MSN Messenger
mase



Joined: 21 Aug 2009
Posts: 23

PostPosted: Mon Aug 24, 2009 4:45 am    Post subject: Reply with quote

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:
./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!
Back to top
View user's profile Send private message
psPea



Joined: 01 Sep 2007
Posts: 64

PostPosted: Mon Aug 24, 2009 4:55 am    Post subject: Reply with quote

if you're using -lSDLmain
the you need to define SDL_main and use that as your main function
_________________
Click ME!
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
mase



Joined: 21 Aug 2009
Posts: 23

PostPosted: Mon Aug 24, 2009 5:08 am    Post subject: Reply with quote

Yes, but the working code doesn't provide a SDL_main function, too.
So how can it run?
_________________
May the force be with us!
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Mon Aug 24, 2009 6:02 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
mase



Joined: 21 Aug 2009
Posts: 23

PostPosted: Mon Aug 24, 2009 8:05 am    Post subject: Reply with quote

No, there isn't. Please check the code, if you don't believe me.
_________________
May the force be with us!
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Mon Aug 24, 2009 8:22 am    Post subject: Reply with quote

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

Code:
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.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group