0
我剛開始C++,很明顯我有着名的LNK2019問題。我在谷歌上漫遊了幾個小時,但沒有解決我的問題。 我的項目是中途編碼的,因爲我將視圖和模型分開。 我與Visual Studio 2010錯誤LNK2019在連接VS2010期間
這裏工作的是其功能不提取的類:
Display.h:
#ifndef DEF_DISPLAY
#define DEF_DISPLAY
#include <Windows.h>
#include <exception>
class Display{
public:
HWND mainWindow, gameWindow;
WNDCLASS mainClass, gameClass;
public:
Display();
static LRESULT CALLBACK mainWindowProc(HWND mainWin, UINT message, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK gameWindowProc(HWND gameWin, UINT message, WPARAM wParam, LPARAM lParam);
**int run();** // This function is not retrieved by the linker.
};
#endif
這裏是Display.cpp:
#include "Display.h"
HINSTANCE instanceMain = 0, instanceGame = 0;
Display::Display(){...}
LRESULT CALLBACK Display::mainWindowProc(HWND mainWin, UINT message, WPARAM wParam, LPARAM lParam){...}
LRESULT CALLBACK Display::gameWindowProc(HWND gameWin, UINT message, WPARAM wParam, LPARAM lParam){...}
int run(){
MSG message;
while(GetMessage(&message, 0, 0, 0)){
TranslateMessage(&message);
DispatchMessage(&message);
}
return message.wParam;
}
最後這裏是我的main.cpp:
#include "Display.h"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow){
Display game;
return game.run();
}
我沒有完成的代碼我的項目,因爲我發現建立時,這個問題:
1> All outputs are up-to-date.
1>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall Display::run(void)" ([email protected]@@QAEHXZ) referenced in function [email protected]
1>C:\Users\glembalis\Documents\Visual Studio 2010\Projects\pendu\Debug\pendu.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
我不知道哪裏可能會出現錯誤。
- Display.h和Display.cpp都包含在項目
- 在項目選項>屬性>鏈接>系統>子系統的「Windows」
- 我不使用外部庫(僅適用於Windows。 h和例外)
編譯器似乎工作正常。我並不在乎該程序是否正常工作,我稍後會糾正它。目前,這個鏈接器問題是我主要關心的問題!我想這只是一個小小的愚蠢的錯誤,但我找不到它!
感謝大家的時間和關注,期待着您的答案!最後,我很抱歉,但英語不是我的母語,我可能寫過一些錯誤。
祝您有美好的一天!
NoobFeeder