Page 1 of 1

Problems linking a Wii example program [SOLVED]

Posted: Mon Jan 25, 2010 9:09 am
by blacksoul
EDIT: Since it was solved, marked it as such :)
---------------------------------------------

Hello,

I want to port a SDL game for the Wii, first of all, I have been trying to install the SDK since 3 last days with no success.

This is the code that I am using (a simple hello world, it doesn't use SDL).

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <gccore.h>
#include <wiiuse/wpad.h>

static void *xfb = NULL;
static GXRModeObj *rmode = NULL;

//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------

	// Initialise the video system
	VIDEO_Init();
	// This function initialises the attached controllers
	WPAD_Init();
	
	// Obtain the preferred video mode from the system
	// This will correspond to the settings in the Wii menu
	rmode = VIDEO_GetPreferredMode(NULL);

	// Allocate memory for the display in the uncached region
	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	
	// Initialise the console, required for printf
	console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
	
	// Set up the video registers with the chosen mode
	VIDEO_Configure(rmode);
	
	// Tell the video hardware where our display memory is
	VIDEO_SetNextFramebuffer(xfb);
	
	// Make the display visible
	VIDEO_SetBlack(FALSE);

	// Flush the video register changes to the hardware
	VIDEO_Flush();

	// Wait for Video setup to complete
	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();


	// The console understands VT terminal escape codes
	// This positions the cursor on row 2, column 0
	// we can use variables for this with format codes too
	// e.g. printf ("\x1b[%d;%dH", row, column );
	printf("\x1b[2;0H");

	printf("Hello World!");

	while(1) {

		// Call WPAD_ScanPads each loop, this reads the latest controller states
		WPAD_ScanPads();

		// WPAD_ButtonsDown tells us which buttons were pressed in this loop
		// this is a "one shot" state which will not fire again until the button has been released
		u32 pressed = WPAD_ButtonsDown(0);

		// We return to the launcher application via exit
		if ( pressed & WPAD_BUTTON_HOME ) exit(0);

		// Wait for the next frame
		VIDEO_WaitVSync();
	}

	return 0;
}
I compile it with:
powerpc-eabi-gcc -O0 -g3 -Wall -c -fmessage-length=0 -c hello.c -I"/home/black/devkitPro/libogc/include" -I"/home/black/devkitPro/devkitPPC/powerpc-eabi/include/c++/4.4.2" -I"/home/black/devkitPro/devkitPPC/powerpc-eabi/include/c++/4.4.2/powerpc-eabi" -I"/home/black/devkitPro/devkitPPC/lib/gcc/powerpc-eabi/4.4.2/include" -I"/home/black/devkitPro/devkitPPC/powerpc-eabi/include"

Program compiles without problem.

I link it with:
powerpc-eabi-gcc hello.o -o hello -L/home/black/devkitPro/libogc/lib/wii -lwiiuse -lbte -logc -lm

and I get this (the same that you can find in this post: http://forums.devkitpro.org/viewtopic.php?f=3&t=1329):

/home/black/devkitPro/libogc/lib/wii/libogc.a(ogc_crt0.o): In function `startup':
(.init+0x3e): undefined reference to `__isIPL'
/home/black/devkitPro/libogc/lib/wii/libogc.a(ogc_crt0.o): In function `startup':
(.init+0x42): undefined reference to `__isIPL'
/home/black/devkitPro/libogc/lib/wii/libogc.a(ogc_crt0.o): In function `startup':
(.init+0x5a): undefined reference to `__bss_end'
/home/black/devkitPro/libogc/lib/wii/libogc.a(ogc_crt0.o): In function `startup':
(.init+0x5e): undefined reference to `__bss_end'
/home/black/devkitPro/libogc/lib/wii/libogc.a(lwp.o): In function `__lwp_sysinit':
lwp.c:(.text.__lwp_sysinit+0xaa): undefined reference to `__stack_end'
lwp.c:(.text.__lwp_sysinit+0xae): undefined reference to `__stack_addr'
lwp.c:(.text.__lwp_sysinit+0xb2): undefined reference to `__stack_end'
lwp.c:(.text.__lwp_sysinit+0xb6): undefined reference to `__stack_addr'
lwp.c:(.text.__lwp_sysinit+0xd6): undefined reference to `__crtmain'
lwp.c:(.text.__lwp_sysinit+0xde): undefined reference to `__crtmain'
/home/black/devkitPro/libogc/lib/wii/libogc.a(irq.o): In function `__irq_init':
irq.c:(.text.__irq_init+0x22): undefined reference to `__intrstack_addr'
irq.c:(.text.__irq_init+0x2a): undefined reference to `__intrstack_addr'
irq.c:(.text.__irq_init+0x32): undefined reference to `__intrstack_end'
irq.c:(.text.__irq_init+0x3a): undefined reference to `__intrstack_end'
/home/black/devkitPro/libogc/lib/wii/libogc.a(system.o): In function `SYS_Init':
system.c:(.text.SYS_Init+0xfe): undefined reference to `__gxregs'
system.c:(.text.SYS_Init+0x106): undefined reference to `__gxregs'
system.c:(.text.SYS_Init+0x1ba): undefined reference to `__Arena1Hi'
system.c:(.text.SYS_Init+0x1c2): undefined reference to `__Arena1Hi'
system.c:(.text.SYS_Init+0x1fa): undefined reference to `__Arena2Lo'
system.c:(.text.SYS_Init+0x202): undefined reference to `__Arena2Lo'
system.c:(.text.SYS_Init+0x23a): undefined reference to `__Arena2Hi'
system.c:(.text.SYS_Init+0x242): undefined reference to `__Arena2Hi'
system.c:(.text.SYS_Init+0x262): undefined reference to `__ipcbufferLo'
system.c:(.text.SYS_Init+0x26a): undefined reference to `__ipcbufferLo'
system.c:(.text.SYS_Init+0x26e): undefined reference to `__ipcbufferHi'
system.c:(.text.SYS_Init+0x27a): undefined reference to `__ipcbufferHi'
system.c:(.text.SYS_Init+0x73a): undefined reference to `__Arena1Lo'
system.c:(.text.SYS_Init+0x73e): undefined reference to `__Arena1Lo'
/home/black/devkitPro/libogc/lib/wii/libogc.a(system.o):(.sdata2.__sys_inIPL+0x0): undefined reference to `__isIPL'
/home/black/devkitPro/libogc/lib/wii/libogc.a(argv.o): In function `__CheckARGV':
argv.c:(.text.__CheckARGV+0x4a): undefined reference to `__Arena1Lo'
argv.c:(.text.__CheckARGV+0x52): undefined reference to `__Arena1Lo'
/home/black/devkitPro/libogc/lib/wii/libogc.a(gx.o): In function `GX_EndDispList':
gx.c:(.text.GX_EndDispList+0x66): undefined reference to `__gxregs'
gx.c:(.text.GX_EndDispList+0x76): undefined reference to `__gxregs'
/home/black/devkitPro/libogc/lib/wii/libogc.a(gx.o): In function `GX_BeginDispList':
gx.c:(.text.GX_BeginDispList+0xd6): undefined reference to `__gxregs'
gx.c:(.text.GX_BeginDispList+0xda): undefined reference to `__gxregs'
/home/black/devkitPro/libogc/lib/wii/libogc.a(gx.o): In function `GX_Init':
gx.c:(.text.GX_Init+0x5a): undefined reference to `__gxregs'
/home/black/devkitPro/libogc/lib/wii/libogc.a(gx.o):gx.c:(.text.GX_Init+0x66): more undefined references to `__gxregs' follow
collect2: ld returned 1 exit status

The environment variables are ok in ~/.bashrc:

export DEVKITPRO=/home/black/devkitPro
export DEVKITPPC=$DEVKITPRO/devkitPPC
PATH=$PATH:$DEVKITPPC/bin

powerpc-eabi-gcc -v returns this:

Using built-in specs.
Target: powerpc-eabi
Configured with: ../../gcc-4.4.2/configure --enable-languages=c,c++,objc --with-cpu=750 --disable-nls --disable-shared --enable-threads --disable-multilib --disable-win32-registry --disable-libstdcxx-pch --target=powerpc-eabi --with-newlib --prefix=/opt/devkitpro/devkitPPC --disable-dependency-tracking --with-bugurl=http://wiki.devkitpro.org/index.php/Bug_Reports --with-pkgversion='devkitPPC release 19'
Thread model: single
gcc version 4.4.2 (devkitPPC release 19)

ls command into ~/devkitPro/devkitPPC/libogc/lib/wii returns this:
libasnd.a libdb.a libfat.a libmad.a libogc.a libSDL_gfx.a libSDL_mixer.a libSDL_ttf.a libtinysmb.a libwiiuse.a libbte.a libdi.a libiso9660.a libmodplay.a libSDL.a libSDL_image.a libSDL_net.a libsmpeg.a libwiikeyboard.a libz.a

I am using OpenSUSE 11.2 but I get the same linking errors with Windows XP.

I am not sure if this is the best place to post this message, if it isn't, please move the post to the right place.

Any help would be highly appreciated.

Thanks.

EDIT: Please ignore this, I have been able to compile it using makefiles, I will use them instead of manual compiling. Thanks anyway.