wxwidgets app in Visual Studio gives error “LNK2019 unresolved external symbol”

旧时模样 提交于 2020-01-24 19:31:06

问题


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

I have compiled the wxwidgets my self in Visual Studio.

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

I went to configuration and added includes directories:

Configuration properties -> C/C++ -> General -> Additional include directories:

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

Configuration properties -> Linker -> Additional Library Directories:

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

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() {

}

回答1:


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

  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.


来源:https://stackoverflow.com/questions/59848356/wxwidgets-app-in-visual-studio-gives-error-lnk2019-unresolved-external-symbol

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!