Linking error with xinput

Recommended Posts

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;
	}
}


 

Edited by suliman

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now