【问题标题】:wxwidgets app in Visual Studio gives error "LNK2019 unresolved external symbol"Visual Studio 中的 wxwidgets 应用程序给出错误“LNK2019 unresolved external symbol”
【发布时间】: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

标签: c++ wxwidgets


【解决方案1】:

你有2个问题(由于下面的评论编辑后)以下问题:

  1. 您正在将应用程序构建为控制台模式应用程序,而不是 GUI 应用程序。虽然也可以从控制台应用程序中使用 wxWidgets,但这可能不是您想要做的,因此请确保项目属性对话框中的“Linker|System|SubSystem”选项设置为“Windows”。
  2. 您的代码中没有 wxIMPLEMENT_APP(cApp); 宏。同样,完全有可能避免它,但这可能不是你的目标,所以只需添加这一行。这个宏定义了你的应用程序的mainWinMain,具体取决于平台。

【讨论】:

  • 糟糕,抱歉,我忽略了它。
猜你喜欢
  • 2013-11-22
  • 2017-03-30
  • 1970-01-01
  • 2021-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-16
相关资源
最近更新 更多