Welcome! Log In Create A New Profile

Advanced

SDL-Wii: undefined reference to main

Posted by Arikado 
SDL-Wii: undefined reference to main
October 04, 2009 04:07PM
Every single time I link SDL-Wii into one of my programs, I get the following error:
c:/devkitpro/devkitppc/bin/../lib/gcc/powerpc-eabi/4.4.1/../../../../powerpc-eabi/lib/crtmain.o: In function `__crtmain':
e:/devkitpro-svn/buildscripts/newlib-1.17.1/libgloss/rs6000/crtmain.c:18: undefined reference to `main'
collect2: ld returned 1 exit status

I was told on the IRC awhile ago that updating to svn libogc and devkitPPC would fix the problem. I finally did, but they didn't fix the problem. This leads to believe that I misusing SDL-Wii.

Suggestions?
Re: SDL-Wii: undefined reference to main
October 04, 2009 09:37PM
Hummm.... I had this issue once, I'm trying to remember how I fixed it. Try a couple of things :

- Check the link order of the libraries ( I think the correct order is on the SDL Wiki page)
- Make sure that your main function is the same prototype as SDL main. (What I use is int main(int argc, char **argv)).
Re: SDL-Wii: undefined reference to main
October 05, 2009 07:15AM
When using sdl, it hijacks the role as main, your main is silently renamed to something else.
Re: SDL-Wii: undefined reference to main
October 09, 2009 10:57PM
Thanks - worked :-)
Re: SDL-Wii: undefined reference to main
October 17, 2009 07:59PM
Quote
henke37
When using sdl, it hijacks the role as main, your main is silently renamed to something else.
Now that I'm actually using it, I can see the presence of this. For curiosity's sake, do you know what code is actually executed first then? When does my program reach to the point of executing the first line of code in my main() ?
Re: SDL-Wii: undefined reference to main
October 17, 2009 10:09PM
Quote
Arikado
Quote
henke37
When using sdl, it hijacks the role as main, your main is silently renamed to something else.
Now that I'm actually using it, I can see the presence of this. For curiosity's sake, do you know what code is actually executed first then? When does my program reach to the point of executing the first line of code in my main() ?

for the Wii it's

/* Do initialisation which has to be done first for the console to work */
/* Entry point */
int main(int argc, char *argv[])
{
#ifdef HW_RVL
	// Wii Power/Reset buttons
	WPAD_Init();
	WPAD_SetPowerButtonCallback((WPADShutdownCallback)ShutdownCB);
	SYS_SetPowerCallback(ShutdownCB);
	SYS_SetResetCallback(ResetCB);
#endif
	PAD_Init();
	WII_InitVideoSystem();
#ifdef HW_RVL
	WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);
	WPAD_SetVRes(WPAD_CHAN_ALL, 640, 480);

	MOUSE_Init();
	KEYBOARD_Init(NULL);
#endif
	/* Call the user's main function */
	return(SDL_main(argc, argv));
}

Re: SDL-Wii: undefined reference to main
November 05, 2009 10:07PM
What does WII_InitVideoSystem() do as opposed to VIDEO_Init()?
Re: SDL-Wii: undefined reference to main
November 05, 2009 10:51PM
It's an internal function in SDL_wiivideo.c:
void
WII_InitVideoSystem()
{
	/* Initialise the video system */
	VIDEO_Init();
	vmode = VIDEO_GetPreferredMode(NULL);

	switch (vmode->viTVMode >> 2)
	{
		case VI_PAL: // 576 lines (PAL 50hz)
			// display should be centered vertically (borders)
			vmode = &TVPal574IntDfScale;
			vmode->xfbHeight = 480;
			vmode->viYOrigin = (VI_MAX_HEIGHT_PAL - 480)/2;
			vmode->viHeight = 480;
			break;

		case VI_NTSC: // 480 lines (NTSC 60hz)
			break;

		default: // 480 lines (PAL 60Hz)
			break;
	}

	/* Set up the video system with the chosen mode */
	VIDEO_Configure(vmode);

	// Allocate the video buffers
	xfb[0] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode));
	xfb[1] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode));

	VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK);
	VIDEO_ClearFrameBuffer(vmode, xfb[1], COLOR_BLACK);
	VIDEO_SetNextFramebuffer (xfb[0]);

	// Show the screen.
	VIDEO_SetBlack(FALSE);
	VIDEO_Flush();
	VIDEO_WaitVSync();
	if (vmode->viTVMode & VI_NON_INTERLACE)
			VIDEO_WaitVSync();
		else
			while (VIDEO_GetNextField())
				VIDEO_WaitVSync();

	/*** Clear out FIFO area ***/
	memset (&gp_fifo, 0, DEFAULT_FIFO_SIZE);

	/*** Initialise GX ***/
	GX_Init (&gp_fifo, DEFAULT_FIFO_SIZE);

	GXColor background = { 0, 0, 0, 0xff };
	GX_SetCopyClear (background, 0x00ffffff);

	SetupGX();
}

Re: SDL-Wii: undefined reference to main
November 05, 2009 11:11PM
Thank-you scanff. You are very helpful :-)

Does it set-up a console? It appears not to?



Edited 1 time(s). Last edit at 11/05/2009 11:13PM by Arikado.
Re: SDL-Wii: undefined reference to main
November 06, 2009 01:04AM
No, it does not set up a console.
Re: SDL-Wii: undefined reference to main
November 06, 2009 01:35AM
Setting up a console would be pointless as it's not visible with GX enabled.
Re: SDL-Wii: undefined reference to main
November 06, 2009 02:48AM
Quote
Tantric
Setting up a console would be pointless as it's not visible with GX enabled.
scanff and I had a discussion on IRC and I realize that now.

Tantric, one of the projects I'm developing is giving me a lot of trouble and I'd like to print text on the screen to be able to debug where the crash occurs. So my question to you is, how would you recommend printing text to the screen in a program which uses SDL?



Edited 1 time(s). Last edit at 11/06/2009 04:13AM by Arikado.
Re: SDL-Wii: undefined reference to main
November 06, 2009 04:36AM
dhewg has written some console code that works in GX, I would suggest using that.
Re: SDL-Wii: undefined reference to main
November 06, 2009 12:49PM
Could you please tell me where I could find it?
Sorry, only registered users may post in this forum.

Click here to login