-2

The #include for the library works normally and Visual Studio 2019 doesn’t point out any errors in the functions. However, when compiling, the following error appears:

code: LNK2019 Description: unresolved external symbol, _main, referenced in function “int __cdecl invoke_main(void)” (?invoke_main@@YAHXZ) File: MSVCRTD.lib(exe_main.obj) Line: 1

The exemple is this: Example The code of the example is this:

// Start of wxWidgets "Hello World" Program
#include <wx/wx.h>

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

wxIMPLEMENT_APP(MyApp);

class MyFrame : public wxFrame
{
public:
    MyFrame();

private:
    void OnHello(wxCommandEvent& event);
    void OnExit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
};

enum
{
    ID_Hello = 1
};

bool MyApp::OnInit()
{
    MyFrame* frame = new MyFrame();
    frame->Show(true);
    return true;
}

MyFrame::MyFrame()
    : wxFrame(nullptr, wxID_ANY, "Hello World")
{
    wxMenu* menuFile = new wxMenu;
    menuFile->Append(ID_Hello, "&Hello...\tCtrl-H",
        "Help string shown in status bar for this menu item");
    menuFile->AppendSeparator();
    menuFile->Append(wxID_EXIT);

    wxMenu* menuHelp = new wxMenu;
    menuHelp->Append(wxID_ABOUT);

    wxMenuBar* menuBar = new wxMenuBar;
    menuBar->Append(menuFile, "&File");
    menuBar->Append(menuHelp, "&Help");

    SetMenuBar(menuBar);

    CreateStatusBar();
    SetStatusText("Welcome to wxWidgets!");

    Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
    Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
    Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
}

void MyFrame::OnExit(wxCommandEvent& event)
{
    Close(true);
}

void MyFrame::OnAbout(wxCommandEvent& event)
{
    wxMessageBox("This is a wxWidgets Hello World example",
        "About Hello World", wxOK | wxICON_INFORMATION);
}

void MyFrame::OnHello(wxCommandEvent& event)
{
    wxLogMessage("Hello world from wxWidgets!");
}

I tried to run this in a "Blank Project" and in a "Console Application" in Visual Studio 2019 community and the same error happened in both projects. What happened? What shoul I do?

Igor
  • 5,620
  • 11
  • 51
  • 103
JMBCODE
  • 15
  • 6
  • I suggest not to use vxpkg. It is known to have bugs in the wxWidgets distribution. Besides I gave you the answer on how to build the library on the other thread. Why do you need multiple copies of it. – Igor Jul 01 '23 at 03:40

1 Answers1

0

I already solved the problem. The error was that the “Linker|System|SubSystem” option in the properties dialog of my project was set to “Console”.

JMBCODE
  • 15
  • 6
  • of course. You tried to run it in the `CONSOLE` project and an empty project, which is also `CONSOLE` by default. – Igor Jul 01 '23 at 13:39
  • Hi ,glad to know you've found the solution to resolve this issue! Please consider accepting it as an answer to change its status to Answered. It will also help others to solve the similar issue. – Minxin Yu - MSFT Jul 03 '23 at 05:41