Jump to content
  • Advertisement
Sign in to follow this  
etsuja

Unknown reason for LNK2001

This topic is 3842 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

I'm trying to use a method from an external library I'm using but I'm getting a linker error and I don't know why. Debug works fine but I get the error for release. I'm trying to call the method from a derrived class. Game_Actor.h
#ifndef _GAME_ACTOR_H
#define _GAME_ACTOR_H

#include "stdafx.h"
#include "Game_Source.h"

class GAME_SOURCE_API Game_Actor
{
public:

	Game_Actor() {}
	~Game_Actor() {}

	Location GetMapLoc( void ) { return m_MapLoc; }
	Location GetWorldLoc( void ) { return m_WorldLoc; }

	void SetMapLoc( Location aLoc ) { m_MapLoc = aLoc; }
	void SetWorldLoc( Location aLoc ) { m_WorldLoc = aLoc; }

private:

	Location m_WorldLoc;
	Location m_MapLoc;

};

#endif

Game_Player.h
#ifndef _GAME_PLAYER_H
#define _GAME_PLAYER_H

#include "Game_Source.h"
#include "Game_Actor.h"

class GAME_SOURCE_API Game_Player : public Game_Actor
{
public:
	Game_Player() {}
	~Game_Player() {}

private:

};

#endif

Here's the exact error: 1>Engine_Main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall Game_Actor::SetMapLoc(struct Location)" (__imp_?SetMapLoc@Game_Actor@@QAEXULocation@@@Z) I'm including Game_Player.h in my globals header which is included in the code I'm trying to call the method from. I'm trying to call SetMapLoc() with an instance of Game_Player and it gives me the linker error. Anyone know what I'm doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
When you add an additional dependency to a project you need to do so for both the debug and release settings. Doing it once won't carry over to both.

Share this post


Link to post
Share on other sites
(Assuming you're using Visual Studio)
Setting the dependencies in the "Project Dependencies" dialog isn't enough. You also need to add the "<name of external>.lib" file to Project Properties->Linker->Additional Dependencies

[EDIT] Damn, I take took long to write posts ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!