Welcome! Log In Create A New Profile


Undefined Reference to WPAD_Init?

Posted by DigitalMan 
Undefined Reference to WPAD_Init?
October 06, 2008 09:46AM
Because the "Hello, world" template program included with DevKitPro causes the Wii to basically hang after execution, I decided my first task should be to make it respond to the Wii remote and exit somehow.

I grabbed some code from an example file, adding "#include " where it belongs, "WPAD_Init();" below "VIDEO_Init();", and two more lines inside what I assume is designed to be an infinite loop, while(1):

if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) exit(0);

Working in Visual C++, this allegedly compiles fine. No errors or warnings, and I can have it show me exactly where each of the WPAD functions is contained in the wpad.h file. If the header definition is removed, it has logical errors to reflect that.

However, even when VC++ thinks it builds perfectly, it does not. The "Output Window" section of the BuildLog.htm states:

Performing Makefile project actions
linking ... WiiTest.elf
WiiTest.o: In function `main':
e:/WiiDev/Projects/WiiTest/source/WiiTest.c(16): undefined reference to `WPAD_Init'
e:/WiiDev/Projects/WiiTest/source/WiiTest.c(50): undefined reference to `WPAD_ScanPads'
e:/WiiDev/Projects/WiiTest/source/WiiTest.c(51): undefined reference to `WPAD_ButtonsDown'
e:/WiiDev/Projects/WiiTest/source/WiiTest.c(50): undefined reference to `WPAD_ScanPads'
e:/WiiDev/Projects/WiiTest/source/WiiTest.c(51): undefined reference to `WPAD_ButtonsDown'
collect2: ld returned 1 exit status
make[1]: *** [/e/WiiDev/Projects/WiiTest/WiiTest.elf] Error 1
make: *** [build] Error 2

I haven't the foggiest idea what this means; "undefined reference" is only supposed to occur when it can't locate the file or functions, but VC++ its self can. No other files located under the DevKitPro install directory have a problem. Is there something obvious I'm missing here?
Re: Undefined Reference to WPAD_Init?
October 06, 2008 12:12PM
Without seeing your code, can't be too certain. However one thing to check: Did you use
#include "wiiuse/wpad.h"
#include <wiiuse/wpad.h>

You should be using the latter. There's a subtle difference in text, but a massive difference in compile

Edited 1 time(s). Last edit at 10/06/2008 12:12PM by whodares.
Re: Undefined Reference to WPAD_Init?
October 06, 2008 12:40PM
whodares: No, if you see his output it ended up compiling just fine; it found the header. The linker failed because his default Makefile is weird and doesn't link to wiiuse.

The problem is that you're not linking to the wiiuse library. In your Makefile, add "-lwiiuse" to the beginning of the LIBS line and everything should be fine.

Also, odd that the default template doesn't include Wiimote stuff, do you have something old? The wii/examples/template for me always includes wiiuse and the snippet you pasted...

EDIT: Also, stop assuming everything is just fine if VC++ says it is. When you compile you're using GNU Make and devkitPro, which isn't aware of Visual C++ nor is VC++ aware of the toolkit. When you want to link to other libraries or add extra include paths, you'll need to do it manually in both your Makefile and VC++ if you want intellisense.

Edited 3 time(s). Last edit at 10/06/2008 12:45PM by AerialX.
Re: Undefined Reference to WPAD_Init?
October 07, 2008 03:24AM
Whatever the difference is between <> and "", it's too subtle to matter - VC++ still thinks all goes well, and the BuildLog contains the exact same errors. The .c file I took the code from used <>, so I did as well.

I believe I'm using the newest version of DevKitPro, I just downloaded it a few days ago. I was told the Makefile already knew where to find everything, but apparently not.

Adding that bit to the LIBS line does have an effect, but not a good one. It seems wpad.h its self links to more files the Makefile can't find, resulting in over 40 new "undefined reference in..." errors. I have to wonder if there would be any disadvantage to making a catch-all Makefile that knows where everything is, to avoid any such errors in the future.

For future reference, my code, only very slightly altered from the base template (<> removed from includes; come on guys, this is a coding forum, why does it respond to HTML brackets?):

#include stdio.h
#include stdlib.h
#include string.h
#include malloc.h
#include ogcsys.h
#include gccore.h
#include wiiuse/wpad.h //Added line

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

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

	switch(VIDEO_GetCurrentTvMode()) {
		case VI_NTSC:
			rmode = &TVNtsc480IntDf;
		case VI_PAL:
			rmode = &TVPal528IntDf;
		case VI_MPAL:
			rmode = &TVMpal480IntDf;
			rmode = &TVNtsc480IntDf;

	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();

	printf(" ");
	printf("This is a test of the Imperial Wii Communication System.");

	while(1) {

		WPAD_ScanPads(); //Added line
		if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) exit(0); //Added line


	return 0;

EDIT: Oh-ho! I think I got it! -lwiiuse isn't enough - for one, it also needs Bluetooth capabilities to connect to the Wii remote. From this tutorial I grabbed the line "LIBS := -lwiiuse -lbte -logc -lm " and it builds perfectly. I'll know whether my coding is right when the TV is free, but for now, I'm just happy I finally got the .dol and .elf files. I am still very much interested in a catch-all Makefile.

Edited 2 time(s). Last edit at 10/07/2008 05:31AM by DigitalMan.
Sorry, only registered users may post in this forum.

Click here to login