Visual Studio 中的 wxwidgets 应用程序给出错误“LNK2019 未解析的外部符号"; [英] wxwidgets app in Visual Studio gives error "LNK2019 unresolved external symbol"

查看:40
本文介绍了Visual Studio 中的 wxwidgets 应用程序给出错误“LNK2019 未解析的外部符号";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 C++ 和 wxwidgets 创建我的第一个程序.当我尝试编译项目时,出现错误.

Im creating my first program with C++ and wxwidgets. When I try to compile the project I get errors.

LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

LNK1120 1 unresolved externals

我已经在 Visual Studio 中自己编译了 wxwidgets.

I have compiled the wxwidgets my self in Visual Studio.

编译后我在 Visual Studio 中创建了一个新的 C++ 空项目.

After compiling I created a new C++ empty project in Visual Studio.

我去配置并添加了包含目录:

I went to configuration and added includes directories:

配置属性 -> C/C++ -> 常规 -> 附加包含目录:

C:\Users\user\source\repos\wxWidgets\include;C:\Users\user\source\repos\wxWidgets\include\msvc

C:\Users\user\source\repos\wxWidgets\include; C:\Users\user\source\repos\wxWidgets\include\msvc

配置属性 -> 链接器 -> 附加库目录:

C:\Users\user\source\repos\wxWidgets\lib\vc_lib

C:\Users\user\source\repos\wxWidgets\lib\vc_lib

然后我添加了 2 个类,cApp 和 cMain.

Then I added 2 classes, cApp and 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个问题(由于下面的评论而编辑后)以下问题:

You have 2 problems (after the edit due to the comment below) the following problem:

  1. 您将应用程序构建为控制台模式应用程序,而不是 GUI 应用程序.虽然也可以从控制台应用程序使用 wxWidgets,但这可能不是您想要做的,因此请确保将项目属性对话框中的链接器|系统|子系统"选项设置为Windows".
  2. 您的代码中没有 wxIMPLEMENT_APP(cApp); 宏.同样,完全有可能避免它,但这可能不是您的目标,因此只需添加此行.该宏用于为您的应用程序定义 mainWinMain,具体取决于平台.
  1. You're building your application as a console mode application and not a GUI one. While it is possible to use wxWidgets from console applications too, this is probably not what you're trying to do, so ensure that the "Linker|System|SubSystem" option in the properties dialog of your project is set to "Windows".
  2. You don't have wxIMPLEMENT_APP(cApp); macro in your code. Again, it is perfectly possible to avoid it, but this is probably not your goal here, so just add this line. This macro is what defines main or WinMain for your application, depending on the platform.

这篇关于Visual Studio 中的 wxwidgets 应用程序给出错误“LNK2019 未解析的外部符号";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆