user1741137
user1741137

Reputation: 5058

Simple example of wxWidgets demo fails to link

I'm trying to learn wxWidgets from zetcode's first gui sample code I made a VisualStudio 2019 empty project, applied the wxwidgets.props property sheet to my project and created files simple.cpp, simple.h, main.cpp and main.h as in the tutorial. The solution explorer shows this: Solution Explorer Screenshot Here is the content of Main.h

#pragma once
#include <wx/wx.h>

class MyApp : public wxApp
{
public:
    virtual bool OnInit();
};

DECLARE_APP(MyApp);

Here is the code of Main.cpp

#include "Main.h"
#include "Simple.h"

IMPLEMENT_APP(MyApp);

bool MyApp::OnInit()
{
    Simple* simple = new Simple(wxT("Simple"));
    simple->Show(true);

    return true;
}

Here is the code of Simple.h

#pragma once
#include <wx/wx.h>

class Simple : public wxFrame
{
public:
    Simple(const wxString& title);

};

Here is the code of Simple.cpp

#include "Simple.h"

Simple::Simple(const wxString& title)
    : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(250, 150))
{
    Centre();
}

Unfortunately, the project would not link with the following error message:

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)   Simple  D:\devt\WxWidgets\ZetCode\MSVCRTD.lib(exe_main.obj) 1   

Upvotes: 0

Views: 469

Answers (1)

user1741137
user1741137

Reputation: 5058

Thanks to David C Rankin who led me to a solution: I went to Project>Configuration Properties>Linker>System>Subsystem and changed it from Console to Windows (/SUBSYSTEM:WINDOWS) This seems to have solved the problem, but I wish someone could explain what is the implication of what I did.

Upvotes: 1

Related Questions