【发布时间】:2020-05-07 22:37:03
【问题描述】:
我正在使用 C++ 和 wxwidgets 创建我的第一个程序。 当我尝试编译项目时出现错误。
LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
LNK1120 1 unresolved externals
我已经在 Visual Studio 中自己编译了 wxwidgets。
编译后,我在 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() {
}
【问题讨论】:
-
不,我没有 int main()。我在哪里可以定义它?我正在使用 wxWidgets。
-
我只有两个类。我正在关注本教程:youtube.com/watch?v=FOIbK4bJKS8
-
我从文档中看到
wxWidgets应该为您实现int main()。我不知道为什么它不这样做。 -
是的,因为“wxIMPLEMENT_APP(cApp)”。
-
您似乎在
cApp的标题中缺少DECLARE_APP(cApp)。不确定示例代码中是否需要它:https://wiki.wxwidgets.org/Hello_World