wxwidgets unresolved external symbol _mainreferend in function int Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
gustxw
Earned a small fee
Earned a small fee
Posts: 12
Joined: Thu Aug 08, 2019 8:41 pm

wxwidgets unresolved external symbol _mainreferend in function int

Post by gustxw »

hey guys im trying to use wxwidgets
with visual studio 2017 and windows 10
but im having these errors when i try to build im in debug mode x86

Code: Select all

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)	Video_WxWidgets	C:\Users\gustx\Desktop\cbworkspace\Video_WxWidgets\Video_WxWidgets\MSVCRTD.lib(exe_main.obj)	1	

Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK1120	1 unresolved externals	Video_WxWidgets	C:\Users\gustx\Desktop\cbworkspace\Video_WxWidgets\Debug\Video_WxWidgets.exe	1	
Attachments
wx-visualstudio.PNG
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 548
Joined: Fri Nov 03, 2006 2:00 pm

Re: wxwidgets unresolved external symbol _mainreferend in function int

Post by stahta01 »

Post your main function in code tags.

You likely failed to declare a main function or declared it wrong.

Edit: I think wxApp or wxAppConsole is the main function in wx apps.
Edit2: IMPLEMENT_APP(CodeBlocksApp) is how Code::Blocks declares its main app.

Tim S.
gustxw
Earned a small fee
Earned a small fee
Posts: 12
Joined: Thu Aug 08, 2019 8:41 pm

Re: wxwidgets unresolved external symbol _mainreferend in function int

Post by gustxw »

ah yes i dont have a main function, i thought that might a prob but idk the internals of wx yet so i thought maybe it might still work in someway, where should i put it?

here is my code
cApp.h

Code: Select all

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

#include "wx/wx.h"

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

class MyFrame : public wxFrame
{
public:
	MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
private:
	void OnHello(wxCommandEvent& event);
	void OnExit(wxCommandEvent& event);
	void OnAbout(wxCommandEvent& event);
	wxDECLARE_EVENT_TABLE();
};


enum
{
	ID_Hello = 1
};
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_Hello, MyFrame::OnHello)
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
wxEND_EVENT_TABLE()
wxIMPLEMENT_APP(cApp);

bool cApp::OnInit()
{
	MyFrame *frame = new MyFrame("Hello World", wxPoint(50, 50), wxSize(450, 340));
	frame->Show(true);
	return true;
}
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
	: wxFrame(NULL, wxID_ANY, title, pos, size)
{
	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!");
}
void MyFrame::OnExit(wxCommandEvent& event)
{
	Close(true);
}
void MyFrame::OnAbout(wxCommandEvent& event)
{
	wxMessageBox("This is a wxWidgets' Hello world sample",
		"About Hello World", wxOK | wxICON_INFORMATION);
}
void MyFrame::OnHello(wxCommandEvent& event)
{
	wxLogMessage("Hello world from wxWidgets!");
}

cApp.cpp

Code: Select all

#include "cApp.h"


cApp::cApp()
{
}


cApp::~cApp()
{
}

User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxwidgets unresolved external symbol _mainreferend in function int

Post by doublemax »

As this is a GUi application under Windows, it should look for WinMain, not main. Check the project properties at Linker -> System and make sure "Subsystem:Windows" is selected.
Use the source, Luke!
gustxw
Earned a small fee
Earned a small fee
Posts: 12
Joined: Thu Aug 08, 2019 8:41 pm

Re: wxwidgets unresolved external symbol _mainreferend in function int

Post by gustxw »

yea i did know about that and set that previously, weirdly i hit build and it built successfully this time then ran and got progressed to vc_.dll not found now instead so i added it and it worked! very weird
but thanks everyone
Post Reply