2013-03-12 93 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

相关问题