[英]Linker error LNK2019 when linking Boost 1.51.0 dynamically in VS2010
[英]Error LNK2019 during linking in VS2010
我最近開始使用C ++,顯然我有着名的LNK2019問題。 我在谷歌上漫游幾個小時,但沒有解決我的問題。 我的項目是半路編碼,因為我將視圖和模型分開。 我使用Visual Studio 2010。
這是沒有檢索其功能的類:
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)" (?run@Display@@QAEHXZ) referenced in function _WinMain@16
1>C:\Users\glembalis\Documents\Visual Studio 2010\Projects\pendu\Debug\pendu.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
我不知道錯誤發生在哪里。
編譯器似乎運行良好。 我真的不在乎程序是否正常工作,我稍后會更正。 目前,這個鏈接器問題是我主要擔心的問題! 我想這只是一個小小的愚蠢的錯誤,但我找不到它!
感謝大家的時間和關注,期待您的回答! 最后,我道歉但英語不是我的母語,我可能寫了一些錯誤。
祝你今天愉快!
NoobFeeder
您的定義(實現)具有錯誤的簽名。
它應該如下所示:
int Display::run(){
這告訴編譯器您的run
是您的Display
類的成員。
目前,您已經實現了一個名為run
的免費功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.