Visual Studio中的wxWidgets链接问题
wxWidgets LINK issue in Visual Studio
我第一次尝试处理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:Users550documentsvisual studio 11ProjectswxWidgitExamplewxWidgitExampleLINK
Error 2 error LNK1120: 1 unresolved externals C:Users550documentsvisual studio 11ProjectswxWidgitExampleDebugwxWidgitExample.exe 1
问题出在哪里?我使用MS Visual Studio,我想我需要使用#pragma
指令吗?
尝试将wxDECLARE_APP(MyApp);
放在定义MyApp的头文件中,将wxIMPLEMENT_APP(MyApp);
放在实现它的cpp文件中。文档中提供了这些宏的描述。
检查Linker->System->SubSystem下的属性表。确保子系统是Windows而不是Console。
您收到的链接器错误通常表明项目配置设置中ansi与unicode设置不匹配。如果您在启用unicode的情况下构建wxApplication,请确保定义了UNICODE
和_UNICODE
。
windows unicode应用程序的入口点是wWinMainCRTStartup
,其中作为非unicode,WinMainCRTStartup
是其入口点。通常,wxWidgets应该在构建框架时为您正确设置。
为了帮助解决未解决的错误,我会尝试在您尝试构建时将此开关传递到链接器。
如果您的示例不使用unicode,那么请使用/ENTRY:WinMainCRTStartup
。
如果是使用unicode的,则使用/ENTRY:wWinMainCRTStartup
。
相关文章:
- 使用jsoncpp库时出现链接问题
- Cmake 链接问题:未定义对 Button::mousePressEvent(QGraphicsSceneMouseE
- 如何将GTest与CMake一起使用?遵循谷歌指南时的链接问题
- 未解决的外部链接问题
- 'make check' GLIBC 运行时的链接问题
- 在树莓派上用libtorch构建程序时的链接问题
- 野牛弹性链接问题
- 与 AWS 开发工具包的链接问题
- Qt & Firebase C++ SDK 在 iOS 上的链接问题
- 链接问题 boost::p ython::numpy.
- 与 32 位共享对象的链接问题
- 在单元测试项目中包括 .c 文件,并从多个 cpp 文件访问它而不会出现链接问题
- 安卓链接问题
- LLVM 传递链接问题:未定义的符号
- Cmake Mac OSX库链接问题:在Linux上进行编译,但在Mac上进行了编译
- 用libclang解析源文件 - 链接问题包括文件
- C / C++链接问题与非常简单的设置
- Zbar 在 vs2015 链接问题
- Vulkan + GLFW + Cmake在Linux环境下的链接问题
- TFS构建由于链接问题而失败