Jump to content
  • Advertisement
suliman

Linking error with xinput

This topic is 405 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement

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

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

Is there some dll i need to include as well?

Edited by suliman

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

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.

Edited by suliman

Share this post


Link to post
Share on other sites

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?

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!