Visual Studio 中的 wxwidgets 应用出现错误 "LNK2019 unresolved external symbol"
wxwidgets app in Visual Studio gives error "LNK2019 unresolved external symbol"
我正在用 C++ 和 wxwidgets 创建我的第一个程序。
当我尝试编译项目时出现错误。
LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
LNK1120 1 unresolved externals
我自己编译了wxwidgets Visual Studio。
编译后我在 Visual Studio 中创建了一个新的 C++ 空项目。
我去配置并添加了包含目录:
配置属性 -> C/C++ -> 常规 -> 附加包含目录:
C:\Users\user\source\repos\wxWidgets\include; C:\Users\user\source\repos\wxWidgets\include\msvc
配置属性 -> 链接器 -> 其他库目录:
C:\Users\user\source\repos\wxWidgets\lib\vc_lib
然后我添加了2个类,cApp和cMain。
cApp.h
#pragma once
#include "wx/wx.h"
#include "cMain.h"
class cApp : public wxApp
{
public:
cApp();
~cApp();
private:
cMain* m_frame1 = nullptr;
public:
virtual bool OnInit();
};
cApp.cpp
#include "cApp.h"
wxIMPLEMENT_APP(cApp);
cApp::cApp() {
}
cApp::~cApp() {
}
bool cApp::OnInit() {
m_frame1 = new cMain();
m_frame1->Show();
return true;
}
cMain.h
#pragma once
#include "wx/wx.h"
class cMain : public wxFrame
{
public:
cMain();
~cMain();
};
cMain.cpp
#include "cMain.h"
cMain::cMain() : wxFrame(nullptr, wxID_ANY, "MyProgram") {
}
cMain::~cMain() {
}
你有2个问题(由于下面的评论而编辑后)以下问题:
- 您正在将应用程序构建为控制台模式应用程序,而不是 GUI 应用程序。虽然也可以从控制台应用程序使用 wxWidgets,但这可能不是您想要做的,因此请确保项目属性对话框中的 "Linker|System|SubSystem" 选项设置为 "Windows"。
您的代码中没有 wxIMPLEMENT_APP(cApp);
宏。同样,完全有可能避免它,但这可能不是您的目标,所以只需添加这一行。这个宏是为您的应用程序定义 main
或 WinMain
的宏,具体取决于平台。
我正在用 C++ 和 wxwidgets 创建我的第一个程序。 当我尝试编译项目时出现错误。
LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
LNK1120 1 unresolved externals
我自己编译了wxwidgets Visual Studio。
编译后我在 Visual Studio 中创建了一个新的 C++ 空项目。
我去配置并添加了包含目录:
配置属性 -> C/C++ -> 常规 -> 附加包含目录:
C:\Users\user\source\repos\wxWidgets\include; C:\Users\user\source\repos\wxWidgets\include\msvc
配置属性 -> 链接器 -> 其他库目录:
C:\Users\user\source\repos\wxWidgets\lib\vc_lib
然后我添加了2个类,cApp和cMain。
cApp.h
#pragma once
#include "wx/wx.h"
#include "cMain.h"
class cApp : public wxApp
{
public:
cApp();
~cApp();
private:
cMain* m_frame1 = nullptr;
public:
virtual bool OnInit();
};
cApp.cpp
#include "cApp.h"
wxIMPLEMENT_APP(cApp);
cApp::cApp() {
}
cApp::~cApp() {
}
bool cApp::OnInit() {
m_frame1 = new cMain();
m_frame1->Show();
return true;
}
cMain.h
#pragma once
#include "wx/wx.h"
class cMain : public wxFrame
{
public:
cMain();
~cMain();
};
cMain.cpp
#include "cMain.h"
cMain::cMain() : wxFrame(nullptr, wxID_ANY, "MyProgram") {
}
cMain::~cMain() {
}
你有2个问题(由于下面的评论而编辑后)以下问题:
- 您正在将应用程序构建为控制台模式应用程序,而不是 GUI 应用程序。虽然也可以从控制台应用程序使用 wxWidgets,但这可能不是您想要做的,因此请确保项目属性对话框中的 "Linker|System|SubSystem" 选项设置为 "Windows"。
您的代码中没有wxIMPLEMENT_APP(cApp);
宏。同样,完全有可能避免它,但这可能不是您的目标,所以只需添加这一行。这个宏是为您的应用程序定义main
或WinMain
的宏,具体取决于平台。