c++ - Visual Studio 中的 wxWidgets 链接问题

标签 c++ visual-studio wxwidgets visual-studio-2010

我第一次尝试处理wxWidgets,我尝试编译下面的Hello World程序:

/*
 * hworld.cpp
 */

#include "wx/wx.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);
}

编译器显示:

Error   1   error LNK2001: unresolved external symbol _WinMainCRTStartup    C:\Users\550\documents\visual studio 11\Projects\wxWidgitExample\wxWidgitExample\LINK
Error   2   error LNK1120: 1 unresolved externals   C:\Users\550\documents\visual studio 11\Projects\wxWidgitExample\Debug\wxWidgitExample.exe  1

问题是什么?我使用 MS Visual Studio,我想我需要使用 #pragma 指令?

最佳答案

尝试将 wxDECLARE_APP(MyApp); 放在定义 MyApp 的头文件中,并将 wxIMPLEMENT_APP(MyApp); 放在实现它的 cpp 文件中。这些宏的描述在 documentation 中可用。 .

关于c++ - Visual Studio 中的 wxWidgets 链接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8999023/

相关文章:

c++ - 异常和错误代码 : mixing them the right way

c# - Visual Studio 可以告诉我哪个引用引发了 NullReferenceException 吗?

wxwidgets - wxWidget : How do change the size of the parent Sizer according to the size of the children sizers?

c++ - 如何向 wxwidgets 类中创建的按钮添加命令?

c++ - 函数仅声明,但仍然有效

python - 为什么 Python 不能捕获 C++ 中引发的异常?

c++ - 如何将 LPARAM lParam 转换为 CString

python - 属性错误: 'Action' object has no attribute 'text1'

c++ - vector 中连续数字的计数

python - pyAV 的 pip 安装失败,退出状态为 1181