Jump to content
  • Advertisement
Sign in to follow this  
MaxDemian

LNK2001 LNK2019 error

This topic is 3628 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, I have a linking error. I have a class cApp like this: (cApp.h)
class cApp
{
private:

protected:

public:
	cApp(void);
	virtual ~cApp(void);

	VOID			SetInstance(HINSTANCE hInstance);

	HWND			GethWnd();
	HINSTANCE		GethInst();

	BOOL			Run();
	BOOL			Error(BOOL fatal, char *Text);
	
	BOOL			Move(long XPos, long YPos);
	BOOL			Resize(long Width, long Height);

	BOOL			ShowMouse(BOOL Show = TRUE);

	static  LRESULT CALLBACK MsgRouter(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

	virtual LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
	{
		return (int)DefWindowProc(hWnd,uMsg,wParam,lParam);
	}

	virtual BOOL Init();
	virtual BOOL Shutdown();
	virtual BOOL Frame();

};

and a class derived from this (MyGame.h):

#include "cApp.h"

class MyGame:public cApp
{
public:
	MyGame(void);
	virtual ~MyGame(void);
	LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
	{
		return (int)DefWindowProc(hWnd,uMsg,wParam,lParam);
	}

	BOOL Init();
	BOOL Shutdown();
	BOOL Frame();
};

Man file:
#include "MyGame.h"

INT WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreInstance,LPSTR CmdLine,int nShow)
{

	MyGame game;
	game.SetInstance(hInstance);
	game.Run();
	return 0;
}

I've got error in: LNK2001: extern symbol "public: __thiscall cApp::cApp(void)" (??0cApp@@QAE@XZ) LNK2001: extern symbol "public: virtual __thiscall cApp::~cApp(void)" (??1cApp@@UAE@XZ) LNK2019: extern symbol "public: __thiscall cApp::cApp(void)" (??0cApp@@QAE@XZ) sreference not resolved "public: __thiscall MyGame::MyGame(void)" (??0@@QAE@XZ) LNK2019: extern symbol "public: int __thiscall cApp::Run(void)" (?Run@cApp@@QAEHXZ) reference not resolved _WinMain@16 LNK2019: extern symbol "public: virtual __thiscall cApp::~cApp(void)" (??1aeApplication@@UAE@XZ) reference not resolved "public: virtual __thiscall MyGame::~MyGame(void)" (??1AppTetris@@UAE@XZ) LNK2019: extern symbol "public: void __thiscall cApp::SetInstance(struct HINSTANCE__ *)" (?SetInstance@cApp@@QAEXPAUHINSTANCE__@@@Z) reference not resolved _WinMain@16 My compiler is MS Visual Studio .Net

Share this post


Link to post
Share on other sites
Advertisement
Go ahead and post the full (applicable) code, then, so we'll know exactly what you're working with and won't be guessing blindly. It'll also get us a step closer to reproducing things locally if it comes to it.

Share this post


Link to post
Share on other sites
OK

cApp clas:

cApp.h


#ifndef __C_APP__
#define __C_APP__

#include <windows.h>

class cApp
{
private:
HINSTANCE m_hInstance;
HWND m_hWnd;
LPVOID m_lpCreateParams;
protected:
char m_Class[MAX_PATH];
char m_Caption[MAX_PATH];

WNDCLASSEX m_wcex;

DWORD m_style;
DWORD m_XPos;
DWORD m_YPos;
DWORD m_Width;
DWORD m_Height;

VOID SethWnd(HWND hWnd);

public:
cApp(void);
virtual ~cApp(void);

VOID SetInstance(HINSTANCE hInstance);

HWND GethWnd();
HINSTANCE GethInst();

BOOL Run();
BOOL Error(BOOL fatal, char *Text);

BOOL Move(long XPos, long YPos);
BOOL Resize(long Width, long Height);

BOOL ShowMouse(BOOL Show = TRUE);

static LRESULT CALLBACK MsgRouter(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

virtual LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return (int)DefWindowProc(hWnd,uMsg,wParam,lParam);
}

virtual BOOL Init();
virtual BOOL Shutdown();
virtual BOOL Frame();

};

#endif




cApp.cpp


#include "cApp.h"

cApp::cApp(void)
{
}
cApp::~cApp(void)
{
}

VOID cApp::SethWnd(HWND hWnd)
{
this->m_hWnd=hWnd;
}

VOID cApp::SetInstance(HINSTANCE hInstance)
{
this->m_hInstance = hInstance;
}
HWND cApp::GethWnd()
{
return this->m_hWnd;
}
HINSTANCE cApp::GethInst()
{
return this->m_hInstance;
}
BOOL cApp::Run()
{

ZeroMemory(&m_wcex,sizeof(m_wcex));

m_wcex.cbSize = sizeof(WNDCLASSEX);
m_wcex.style = m_style;
m_wcex.lpfnWndProc = (WNDPROC)MsgRouter;
m_wcex.cbClsExtra = 0;
m_wcex.cbWndExtra = 0;
m_wcex.hInstance = m_hInstance;
m_wcex.hIcon = NULL;
m_wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
m_wcex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
m_wcex.lpszMenuName = NULL;
m_wcex.lpszClassName = m_Class;
m_wcex.hIconSm = NULL;

if(!RegisterClassEx(&m_wcex))
{
Error(TRUE,"No se pudo registrar la clase");
return FALSE;
}

m_hWnd = CreateWindow(
m_Class, //Clase de la ventana
m_Caption, //Titulo de la aplicacion
m_style, //Estilo de ventana
m_XPos, //Posicion en x de windows
m_YPos, //Posicion en y de windows
m_Width, //Ancho de la ventana
m_Height, //Alto de la ventana
NULL, //parent window
NULL, //menu
m_hInstance, //Instancia de la aplicacion
(LPVOID)this); //Parametros extras

if(!m_hWnd)
{
Error(true,"No se pudo crear la ventana");
return FALSE;
}

ShowWindow(m_hWnd,SW_SHOW);//Mostramos la ventana
UpdateWindow(m_hWnd);//Refrescamos la ventana
SetFocus(m_hWnd);//Establecemos la ventana como activa

if(Init())
{
Frame();
}

return TRUE;
}
BOOL cApp::Error(BOOL fatal, char *Text)
{
MessageBox(m_hWnd,Text,m_Caption,(fatal)?MB_ICONERROR:MB_ICONWARNING);
return TRUE;
}

LRESULT CALLBACK cApp::MsgRouter(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){

aeApplication * aeWnd=0;

LONG user_data = GetWindowLong(hWnd, GWL_USERDATA);

if(user_data==0)
{

if(uMsg == WM_CREATE)
{
CREATESTRUCT * creation = reinterpret_cast<CREATESTRUCT *>(lParam);
aeWnd = reinterpret_cast<aeApplication *>(creation->lpCreateParams);
::SetWindowLong(hWnd, GWL_USERDATA, reinterpret_cast<long>(aeWnd));

aeWnd->SethWnd(hWnd);
}
else
aeWnd = reinterpret_cast<aeApplication *>(user_data);
}

return aeWnd->WndProc(hWnd,uMsg,wParam,lParam);

}

BOOL cApp::Init() {
return TRUE;
}
BOOL cApp::Shutdown() {
return TRUE;
}
BOOL cApp::Frame() {
return TRUE;
}




My Game class:


MyGame.h

#ifndef __APP_TETRIS__
#define __APP_TETRIS__

#include "cApp.h"
#include <string.h>

class MyGame:public cApp
{
public:
MyGame(void);
virtual ~MyGame(void);
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return (int)DefWindowProc(hWnd,uMsg,wParam,lParam);
}

BOOL Init();
BOOL Shutdown();
BOOL Frame();
};

#endif




MyGame.cpp


#include "MyGame.h"

MyGame::MyGame(void):aeApplication()
{
strcpy(this->m_Caption,"Tetris");
}

MyGame::~MyGame(void)
{
}
BOOL MyGame::Init()
{
return TRUE;
}
BOOL MyGame::Shutdown()
{
return TRUE;
}
BOOL MyGame::Frame()
{
return TRUE;
}




main:


#include "MyGame.h"

INT WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreInstance,LPSTR CmdLine,int nShow)
{

MyGame game;
game.SetInstance(hInstance);
game.Run();
return 0;
}


Share this post


Link to post
Share on other sites
Does this compile for you, or are their compilation errors in addition to your linker errors? With some changes, it compiled and linked fine for me (on VS2005). I'm sure they're not the right changes, as I'm not sure what aeApplication is, but here's the summary:

In MyGame.cpp
aeApplication is undefined. Is this a class of yours?
Old: MyGame::MyGame(void):aeApplication()
New: MyGame::MyGame(void):cApp()

In cApp.cpp
Again, aeApplication is undefined.
Old:
LRESULT CALLBACK cApp::MsgRouter(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){

aeApplication * aeWnd=0;

LONG user_data = GetWindowLong(hWnd, GWL_USERDATA);

if(user_data==0)
{

if(uMsg == WM_CREATE)
{
CREATESTRUCT * creation = reinterpret_cast<CREATESTRUCT *>(lParam);
aeWnd = reinterpret_cast<aeApplication *>(creation->lpCreateParams);
::SetWindowLong(hWnd, GWL_USERDATA, reinterpret_cast<long>(aeWnd));

aeWnd->SethWnd(hWnd);
}
else
aeWnd = reinterpret_cast<aeApplication *>(user_data);
}

return aeWnd->WndProc(hWnd,uMsg,wParam,lParam);

}

New:

LRESULT CALLBACK cApp::MsgRouter(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
return NULL;
}
You'll have to sort that out, but it shouldn't change anything link-time.

More compilation errors in cApp::Run :
Old: m_wcex.lpszClassName = m_Class;
New: //m_wcex.lpszClassName = m_Class;

Old: m_hWnd = CreateWindow(.......
New: //m_hWnd = CreateWindow(.......

After getting it to compile, it linked without a problem. So, are you sure that these linker errors are the only ones you're running into? If so, post everything that somebody else would need to compile and otherwise build, and we'll go from there.

Share this post


Link to post
Share on other sites
I'm sry, aeApplication is cApp, I forgot to change it when I posted it. Im using Visual Studio 2003 or .net
I also have cApp files in other path (not proyect), but I addded the path into the proyect

I dont understand why u do this:

Quote:
Original post by jouley


More compilation errors in cApp::Run :
Old: m_wcex.lpszClassName = m_Class;
New: //m_wcex.lpszClassName = m_Class;

Old: m_hWnd = CreateWindow(.......
New: //m_hWnd = CreateWindow(.......




why u comment?

PS: I dont have any syntaxis error, only linking errors

Share this post


Link to post
Share on other sites
Quote:
Original post by MaxDemian
I'm sry, aeApplication is cApp, I forgot to change it when I posted it. Im using Visual Studio 2003 or .net
I also have cApp files in other path (not proyect), but I addded the path into the proyect

See what happens if the files are in the project path. The cApp files seem to be the basis of problems, so let's simplify things as much as possible. If that works, then you may need to change some project settings in the "Linker" category to let it know where you're keeping the compiled cApp object file if you want to keep it in a separate directory.

Quote:
why u comment?

It was a quick and easy way to get rid of compilation errors. The correct way would be to cast to LPCWSTRs, but if you aren't having them, I guess VS.Net lets you get away with it.

I undid all the comments, and changed aeApplication to cApp, still no problems. Move the files into the project and see how that goes.

Share this post


Link to post
Share on other sites
Quote:
Original post by MaxDemian
Ok, I moved all files into the proyect but still the same problem :S

I just made a new VS.Net (2003) solution and project, added new source/header files, copied/pasted your code, and built it, no problems.

After removing the path that you added from your project (it could still be looking for/building object files there), the next step would be to follow the steps I followed. If there aren't many more files in your project, this shouldn't take more than a few minutes.

Failing that, we'll go through the important project settings and see if anything isn't what it should be.

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!