简体   繁体   English

wxWidgets Visual Studio中的LINK问题

[英]wxWidgets LINK issue in Visual Studio

I am trying to deal with wxWidgets for the first time, I tried to compile the below Hello World program: 我是第一次尝试处理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);
}

The compiler showed: 编译器显示:

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

What is the problem ? 问题是什么 ? I use MS Visual Studio, I guess I need to use #pragma directive? 我使用MS Visual Studio,我想我需要使用#pragma指令?

Try putting wxDECLARE_APP(MyApp); 尝试使用wxDECLARE_APP(MyApp); in the header file where MyApp is defined and wxIMPLEMENT_APP(MyApp); 在定义MyApp的头文件和wxIMPLEMENT_APP(MyApp); in the cpp file where it is implemented. 在cpp文件中实现它。 The description of these macros is avaliable in the documentation . 这些宏的描述在文档中是可用的。

Check your property sheets under Linker->System->SubSystem. 检查链接器 - >系统 - >子系统下的属性表。 Make sure the subsystem is Windows and not Console. 确保子系统是Windows而不是控制台。

That linker error you're getting usually indicates a mismatch in your project configuration settings between ansi vs unicode setup. 您获得的链接器错误通常表示ansi与unicode设置之间的项目配置设置不匹配。 If you're building your wxApplication with unicode enabled make sure UNICODE and _UNICODE are defined. 如果您在启用unicode的情况下构建wxApplication,请确保已定义UNICODE_UNICODE

The entry point for a windows unicode application is wWinMainCRTStartup where as a non-unicode one has WinMainCRTStartup as its entry point. Windows unicode应用程序的入口点是wWinMainCRTStartup ,其中作为非unicode的应用程序将WinMainCRTStartup作为其入口点。 Normally wxWidgets should have that setup correctly for you when you built the framework. 通常,wxWidgets在构建框架时应该正确地为您设置。

To help troubleshoot your unresolved error I would try passing this switch to the linker when you attempt to build. 为了帮助解决您未解决的错误,我会尝试在您尝试构建时将此开关传递给链接器。

If you're example is not using unicode then use /ENTRY:WinMainCRTStartup . 如果您的示例不使用unicode,请使用/ENTRY:WinMainCRTStartup

If you're example is using unicode then use /ENTRY:wWinMainCRTStartup . 如果你的例子使用unicode,那么使用/ENTRY:wWinMainCRTStartup

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM