Skip to main content
GameDev.net gamedev.net
🔒 Locked

Linking error with xinput

Started by suliman Sep 15, 2017 at 8:30 AM 7 replies 6.7k views
Original Post
suliman
suliman

Hi

Im trying to get xinput to work for controller support. Im copying Xinput9_1_0.lib to a folder which Im including in a c++ library path in visual studio 2013.

I still get:


Error    3    error LNK2019: unresolved external symbol _XInputGetState@8 referenced in function "public: void __thiscall keyHandler::controllerConnected(void)" (?controllerConnected@keyHandler@@QAE_NXZ)    C:\Dropbox\PROJECT\code\games\post\source\Main.obj    zombies

Thats a linker error right? Did i do something wrong?

This is what im tryiong to run:


void controllerConnected(){
	int controllerId = -1;

	for (DWORD i = 0; i < XUSER_MAX_COUNT && controllerId == -1; i++)
	{
		XINPUT_STATE state;
		ZeroMemory(&state, sizeof(XINPUT_STATE));

		if (XInputGetState(i, &state) == ERROR_SUCCESS)
			controllerId = i;
	}
}


Kylotan
Kylotan

It's not enough to just have the library on the path; you need to tell the linker to use that library. I think in Visual Studio 2013 it'll be under the project properties, in Linker / Input / Additional Dependencies, or something like that.

suliman
suliman

I added it, cleaned and rebuilt but still same error message, unfortunately.

Is there some dll i need to include as well?

Kylotan
Kylotan

No, linker errors are about library files. Lacking a DLL will typically just make it fail at run time. Make sure you've typed the library name correctly (maybe consult docs to check this), make sure you've typed it in the right place, and make sure it's the right library for the function you're using.

suliman
suliman

It is. But still not working...

It's xinput on a win 10 machine. All sources i find says this is what i should do, still no go.

Kylotan
Kylotan

Are you explicitly telling that project to link in xinput.lib?

suliman
suliman

Yey! That did the trick! Thanks!

But im confused, the file is actually called Xinput9_1_0.lib. So why does linking to xinput.lib work?

StrangeZak
StrangeZak

If im correct, Xinput9_1_0.lib was for the XInput lib that shipped with Vista but i could be wrong. This whole versioning thing is kinda a mess, and i've had issues with this when shipping code before. To fix this i just ended up grabbing the function pointers from the xinput dll instead of hard linking against the lib.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.