2013-03-12 92 views
0

我試圖建立一個最小的wxWidgets應用程序,儘可能小的尺寸是很容易的。 (對我來說很簡單,就是這樣)。wxWidgets編譯錯誤(致命錯誤LNK1120:26無法解析的外部)

這是一個Hello World GUI程序,它不會執行任何其他操作。所以,就我所知,我只需要使用Visual C++ 2008 Express Edition在/ MT模式下構建的wxBase和wxCore。

我的應用程序是這樣的:

#include "wx/app.h" 
#include "wx/frame.h" 
#include "wx/menu.h" 
#include "wx/statusbr.h" 
#include "wx/msgdlg.h" 

class MyApp: public wxApp 
{ 
    virtual bool OnInit(); 
}; 

class MyFrame: public wxFrame 
{ 
public: 

    MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); 

    void OnQuit(wxCommandEvent& event); 
    void OnAbout(wxCommandEvent& event); 

    DECLARE_EVENT_TABLE() 
}; 

enum 
{ 
    ID_Quit = 1, 
    ID_About, 
}; 

BEGIN_EVENT_TABLE(MyFrame, wxFrame) 
    EVT_MENU(ID_Quit, MyFrame::OnQuit) 
    EVT_MENU(ID_About, MyFrame::OnAbout) 
END_EVENT_TABLE() 

IMPLEMENT_APP(MyApp) 

bool MyApp::OnInit() 
{ 
    MyFrame *frame = new MyFrame(_("Hello World"), wxPoint(50, 50), 
            wxSize(450,340)); 
    frame->Show(true); 
    SetTopWindow(frame); 
    return true; 
} 

MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) 
: wxFrame(NULL, -1, title, pos, size) 
{ 
    wxMenu *menuFile = new wxMenu; 

    menuFile->Append(ID_About, _("&About...")); 
    menuFile->AppendSeparator(); 
    menuFile->Append(ID_Quit, _("E&xit")); 

    wxMenuBar *menuBar = new wxMenuBar; 
    menuBar->Append(menuFile, _("&File")); 

    SetMenuBar(menuBar); 

    CreateStatusBar(); 
    SetStatusText(_("Welcome to wxWidgets!")); 
} 

void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) 
{ 
    Close(TRUE); 
} 

void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) 
{ 
    wxMessageBox(_("This is a wxWidgets Hello world sample"), 
        _("About Hello World"), 
        wxOK | wxICON_INFORMATION, this); 
} 

它在wxWidgets documentation的Hello World程序的近完全相同的副本。我只是改變了包含文件。順便說一句,用#include "wx/wx.h"代替它們也不能解決問題。

構建錯誤,我得到的是:

test.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall wxApp::Initialize(int &,wchar_t * *)" ([email protected]@@[email protected]) 
test.obj : error LNK2001: unresolved external symbol "protected: void __thiscall wxStringBase::InitWith(wchar_t const *,unsigned int,unsigned int)" ([email protected]@@[email protected]) 
test.obj : error LNK2001: unresolved external symbol "wchar_t const * const wxEmptyString" ([email protected]@3PB_WB) 
test.obj : error LNK2001: unresolved external symbol "wchar_t const * const wxStatusLineNameStr" ([email protected]@3QB_WB) 
test.obj : error LNK2001: unresolved external symbol "wchar_t const * const wxFrameNameStr" ([email protected]@3QB_WB) 
C:\Users\microsoft\Documents\Visual Studio 2008\Projects\wxAnother\Release\wxAnother.exe : fatal error LNK1120: 5 unresolved externals 

我要包括我對項目的屬性所做的所有更改,但我注意到,所有這些錯誤有事情做與wchar_t,這可能是足以讓某人告訴我是什麼導致了錯誤。

什麼原因導致這些煩人的未解決的外部錯誤,我該如何解決問題(擺脫它們)?

回答

1

可能您將wxWidgets庫編譯爲多線程DLL,並且您的項目是多線程的。或者(因爲所有的錯誤在描述中都有字符串參數),你的wx庫用多字節字符集和應用程序編碼爲Unicode或反之亦然。

你還沒有提到你在LInker - > Input - > Additional Dependencies中提到的wx庫。

+0

罪魁禍首是Unicode的設置。我已經編譯wxWdigets而不使用Unicode,但我的應用程序的設置具有Unicode。更改了項目中的設置,並解決了問題。謝謝! – 2013-03-12 11:23:10

0

這聽起來像你試圖超越編譯器/鏈接器。

爲什麼?

如果你真的有理由需要一個小的可執行文件大小,那麼wxWidgets是不可行的。看看FLTK http://fltk.org/

+0

是什麼讓你覺得呢?我只包含所需的wxWidgets庫,以將可執行文件的大小降到最低,同樣的事情也有數百個其他用戶也嘗試過。 – 2013-03-12 11:25:58

+0

幾十年的經驗讓我覺得這一點:-)大約一百年前,當編譯器和連接器更簡單的事務我花了很多時間擔心如何優化它們的使用。現在,不是那麼多。 – ravenspoint 2013-03-12 11:45:18

+0

如果我聽起來粗魯,道歉。但說實話,我已經閱讀過好幾次了,現在的大小真的不算什麼大不了?我從Qt轉到wxWidgets只是因爲動態鏈接的Qt應用程序大約是5 MB,我認爲它太多了。你不同意嗎? – 2013-03-12 13:51:50

相關問題