- Visit https://cygwin.com/ and download the GUI installer setup-x86_64.exe
- The installer will want to know where to put the files. C:\cygwin64 is the best choice; all lower-case and no spaces.
- It will also ask where to put the package files or installation source. I like to keep mine in my Downloads folder
C:\Users\Patrick\Downloads\Cygwin-Packages
- Next it will ask how to reach the Internet.
- After that it will ask you to choose a mirror. I like mirros.kernal.org. You should pick something you're familiar with.
- If the above went well you will see the package manager. Here you will select the packages to install. At a minimum you'll need:
- gcc-core
- gcc-g++
- cmake
- mingw64-x86_64-gcc-core
- mingw64-x86_64-gcc-g++
- mingw64-x86_64-wxWidgets3.0
Take the latest version of each package. The installer will automatically add package dependencies to install your choices. If you'd like to see how it's done you can watch this YouTube Video
- Cygwin64 should have installed a terminal for you in
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Cygwin
The rest of the steps in this note take place within that application in the default (bash) shell.
cd ~
mkdir hello_wxwidgets
cd hello_wxwidgets
- Create a file named
main.cpp
containing:
// wxWidgets "Hello world" Program
// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
class MyApp : public wxApp {
public:
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(MyApp);
bool MyApp::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!");
}
- Create a file name
CMakeLists.txt
containing:
cmake_minimum_required(VERSION 3.14)
project(Hello_WxWidgets)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_FIND_DEBUG_MODE ON)
set(CMAKE_CXX_STANDARD 17)
# This prevents a warning dialog about library version mismatch.
add_definitions(-D__GXX_ABI_VERSION=1009)
add_executable(Hello main.cpp)
set(MINGW /usr/x86_64-w64-mingw32/sys-root)
# This allows the find_package script to find wx-config-3.0.
LIST(APPEND CMAKE_PROGRAM_PATH ${MINGW}/mingw/bin)
set(wxWidgets_USE_DEBUG ON)
set(wxWidgets_USE_UNICODE ON)
find_package(wxWidgets REQUIRED net gl core base)
include(${wxWidgets_USE_FILE})
target_link_libraries(Hello ${wxWidgets_LIBRARIES})
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=/bin/x86_64-pc-cygwin-gcc.exe -DCMAKE_CXX_COMPILER=/bin/x86_64-w64-mingw32-g++.exe -G "CodeBlocks - Unix Makefiles" -S ~/hello_wxwidgets -B ~/hello_wxwidgets/cmake-build-debug
cmake --build ~/hello_wxwidgets/cmake-build-debug --target Hello -- -j 4
./cmake-build-debug/Hello.exe