Sign in to follow this  

Unknown reason for LNK2001

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

This topic is 3629 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.

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

Sign in to follow this