此问题已在此处有答案:
What is an undefined reference/unresolved external symbol error and how do I fix it?(39答案)
1小时前关闭
库的#include正常工作,Visual Studio 2019没有指出函数中的任何错误。但是,编译时会出现以下错误:
产品编号:LNK 2019产品描述:函数“int __cdecl invoke_main(void)”中引用的未解析外部符号_main(?invoke_main@@YAHXZ)文件:MSVCRTD.lib(exe_main.obj)行:1
这个例子是这样的:Example示例代码如下:
// Start of wxWidgets "Hello World" Program
#include <wx/wx.h>
class MyApp : public wxApp
{
public:
bool OnInit() override;
};
wxIMPLEMENT_APP(MyApp);
class MyFrame : public wxFrame
{
public:
MyFrame();
private:
void OnHello(wxCommandEvent& event);
void OnExit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
};
enum
{
ID_Hello = 1
};
bool MyApp::OnInit()
{
MyFrame* frame = new MyFrame();
frame->Show(true);
return true;
}
MyFrame::MyFrame()
: wxFrame(nullptr, wxID_ANY, "Hello World")
{
wxMenu* menuFile = new wxMenu;
menuFile->Append(ID_Hello, "&Hello...\tCtrl-H",
"Help string shown in status bar for this menu item");
menuFile->AppendSeparator();
menuFile->Append(wxID_EXIT);
wxMenu* menuHelp = new wxMenu;
menuHelp->Append(wxID_ABOUT);
wxMenuBar* menuBar = new wxMenuBar;
menuBar->Append(menuFile, "&File");
menuBar->Append(menuHelp, "&Help");
SetMenuBar(menuBar);
CreateStatusBar();
SetStatusText("Welcome to wxWidgets!");
Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
}
void MyFrame::OnExit(wxCommandEvent& event)
{
Close(true);
}
void MyFrame::OnAbout(wxCommandEvent& event)
{
wxMessageBox("This is a wxWidgets Hello World example",
"About Hello World", wxOK | wxICON_INFORMATION);
}
void MyFrame::OnHello(wxCommandEvent& event)
{
wxLogMessage("Hello world from wxWidgets!");
}```
I tried to run this in a "Blank Project" and in a "Console Application" in Visual Studio 2019 community and the same error happened in both projects.
What happened? What shoul I do?
2条答案
按热度按时间z8dt9xmd1#
我已经解决了问题。错误是“链接器|系统|我的项目属性对话框中的“子系统”选项被设置为“控制台”。
xn1cxnb42#
我没有看到任何
main()
函数定义在您的代码通常你会得到这个错误,因为没有找到
main
函数尝试添加