Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save patrickmoffitt/30684ec23fe82eabe0e3609cab2425b2 to your computer and use it in GitHub Desktop.
Save patrickmoffitt/30684ec23fe82eabe0e3609cab2425b2 to your computer and use it in GitHub Desktop.
Step-by-step instructions for installing Cygwin64, wxWidgets 3.0, minGW-W64, and CMake on Windows 10 for the purpose of building and running the Hello World! demo application.

How to Build wxWidgets 3.0 Hello World! on Windows 10 with Cygwin64, minGW-W64, and CMake

Install Cygwin64, minGW-W64, and CMake

  1. Visit https://cygwin.com/ and download the GUI installer setup-x86_64.exe
  2. The installer will want to know where to put the files. C:\cygwin64 is the best choice; all lower-case and no spaces.
  3. 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
  4. Next it will ask how to reach the Internet.
  5. After that it will ask you to choose a mirror. I like mirros.kernal.org. You should pick something you're familiar with.
  6. 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

Launch a Cygwin Terminal

  • 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.

Hello World!

  1. cd ~
  2. mkdir hello_wxwidgets
  3. cd hello_wxwidgets
  4. 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!");
}

Configure CMake

  1. 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})

Generate the Makefiles

  1. 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

Build Hello wxWidgets

  1. cmake --build ~/hello_wxwidgets/cmake-build-debug --target Hello -- -j 4

Run Hello wxWidgets

  1. ./cmake-build-debug/Hello.exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment