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() {
}
wxWidgets
is supposed to implementint main()
for you. I am not sure why its not doing that. – drescherjmDECLARE_APP(cApp)
in your header forcApp
. Not sure if that is needed its in the example code: https://wiki.wxwidgets.org/Hello_World – drescherjm