【发布时间】:2012-02-18 10:03:45
【问题描述】:
我是第一次尝试处理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 指令?
【问题讨论】:
-
能否提供调用编译链接的命令行?
-
这是您第一次使用 wxWidgets。我已经使用它多年了,我应该推荐你也试试 Qt。你会发现 Qt 更可爱 ;-) 将 QtCreator 与 Qt 4.8 一起使用,尝试示例你会发现不同。
标签: c++ visual-studio wxwidgets visual-studio-2010