PB’s Guide to Starting with wxWidgets on Microsoft Windows with MinGW and Code::Blocks

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.
FrankR
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri Dec 02, 2022 9:58 am

Re: PB’s Guide to Starting with wxWidgets on Microsoft Windows with MinGW and Code::Blocks

Post by FrankR »

PB wrote: Sun Dec 04, 2022 1:12 pm Firstly, this has nothing to do with my guide. Please do not post such questions in the Guide thread, start a new topic in the appropriate forum section.
Sorry for probably using the wrong thread, but I only followed all the steps of your guide and the test-app described in chapter 4.5 produced these warnings. So I just wanted to let you know and was hoping you could point me to a mistake I made. I did not change anything in the code!
PB wrote: Sun Dec 04, 2022 1:12 pm Secondly, deprecation has nothing to do with release or debug build but the wxWidgets version. I am also quite sure it is not wxWidgets "own" issue but the user code issue. If you did not write the code, perhaps you are using a rather outdated (the two methods you posted were deprecated many years ago) tool doing that.
I know that these warnings have nothing to do with relase or debug build. I just wanted to say that I built wxWidgets 3.2.1 that has been announced as a stable release. IMHO a stable realease should not produce warnings when used in a correct way. Right? If so, there must be an error in the build process I was following (maybe my mistake!) or in that tiny app that has been produced by the wizard in C::B.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: PB’s Guide to Starting with wxWidgets on Microsoft Windows with MinGW and Code::Blocks

Post by ONEEYEMAN »

Hi,
As PB already asked - are you trying to revive/build the project that was using (much) older version of wxWidgets?
Just use newer API - check the documentation and 'incompatible changes" file from distribution.

Thank you.
FrankR
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri Dec 02, 2022 9:58 am

Re: PB’s Guide to Starting with wxWidgets on Microsoft Windows with MinGW and Code::Blocks

Post by FrankR »

ONEEYEMAN wrote: Sun Dec 04, 2022 5:18 pm Hi,
As PB already asked - are you trying to revive/build the project that was using (much) older version of wxWidgets?
How could I use a muc older version of wxWidgets? I did nothing else than following PBs instruction step by step. I downloaded wxWidgets 3.2.1 and compiled it like described by PB. The application I compiled has been produced also only using PBs instructions. I did not (willingly) change anything.

Here is the code:
1. GUIFrame.cpp

Code: Select all

///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Feb 17 2007)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////

#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__

#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif //WX_PRECOMP

#include "GUIFrame.h"

///////////////////////////////////////////////////////////////////////////
BEGIN_EVENT_TABLE( GUIFrame, wxFrame )
    EVT_CLOSE( GUIFrame::_wxFB_OnClose )
    EVT_MENU( idMenuQuit, GUIFrame::_wxFB_OnQuit )
    EVT_MENU( idMenuAbout, GUIFrame::_wxFB_OnAbout )
END_EVENT_TABLE()

GUIFrame::GUIFrame( wxWindow* parent, int id, wxString title, wxPoint pos, wxSize size, int style ) : wxFrame( parent, id, title, pos, size, style )
{
    this->SetSizeHints( wxDefaultSize, wxDefaultSize );
    
    mbar = new wxMenuBar( 0 );
    wxMenu* fileMenu;
    fileMenu = new wxMenu();
    wxMenuItem* menuFileQuit = new wxMenuItem( fileMenu, idMenuQuit, wxString( wxT("&Quit") ) + wxT('\t') + wxT("Alt+F4"), wxT("Quit the application"), wxITEM_NORMAL );
    fileMenu->Append( menuFileQuit );
    mbar->Append( fileMenu, wxT("&File") );
    wxMenu* helpMenu;
    helpMenu = new wxMenu();
    wxMenuItem* menuHelpAbout = new wxMenuItem( helpMenu, idMenuAbout, wxString( wxT("&About") ) + wxT('\t') + wxT("F1"), wxT("Show info about this application"), wxITEM_NORMAL );
    helpMenu->Append( menuHelpAbout );
    mbar->Append( helpMenu, wxT("&Help") );
    this->SetMenuBar( mbar );
    
    statusBar = this->CreateStatusBar( 2, wxST_SIZEGRIP, wxID_ANY );
}
2. testApp.cpp

Code: Select all

/***************************************************************
 * Name:      testApp.cpp
 * Purpose:   Code for Application Class
 * Author:    FR ()
 * Created:   2022-12-03
 * Copyright: FR ()
 * License:
 **************************************************************/

#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif

#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__

#include "testApp.h"
#include "testMain.h"

IMPLEMENT_APP(testApp);

bool testApp::OnInit()
{
    testFrame* frame = new testFrame(0L);
    frame->SetIcon(wxICON(aaaa)); // To Set App Icon
    frame->Show();

    return true;
}
3. testMain.cpp

Code: Select all

/***************************************************************
 * Name:      testMain.cpp
 * Purpose:   Code for Application Frame
 * Author:    FR ()
 * Created:   2022-12-03
 * Copyright: FR ()
 * License:
 **************************************************************/

#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif

#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__

#include "testMain.h"

//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__WXMAC__)
        wxbuild << _T("-Mac");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}


testFrame::testFrame(wxFrame *frame)
    : GUIFrame(frame)
{
#if wxUSE_STATUSBAR
    statusBar->SetStatusText(_("Hello Code::Blocks user!"), 0);
    statusBar->SetStatusText(wxbuildinfo(short_f), 1);
#endif
}

testFrame::~testFrame()
{
}

void testFrame::OnClose(wxCloseEvent &event)
{
    Destroy();
}

void testFrame::OnQuit(wxCommandEvent &event)
{
    Destroy();
}

void testFrame::OnAbout(wxCommandEvent &event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}
4. GUIFrame.h

Code: Select all

///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Feb 17 2007)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////

#ifndef __GUIFrame__
#define __GUIFrame__

// Define WX_GCH in order to support precompiled headers with GCC compiler.
// You have to create the header "wx_pch.h" and include all files needed
// for compile your gui inside it.
// Then, compile it and place the file "wx_pch.h.gch" into the same
// directory that "wx_pch.h".
#ifdef WX_GCH
#include <wx_pch.h>
#else
#include <wx/wx.h>
#endif

#include <wx/menu.h>

///////////////////////////////////////////////////////////////////////////

#define idMenuQuit 1000
#define idMenuAbout 1001

///////////////////////////////////////////////////////////////////////////////
/// Class GUIFrame
///////////////////////////////////////////////////////////////////////////////
class GUIFrame : public wxFrame 
{
    DECLARE_EVENT_TABLE()
    private:
        
        // Private event handlers
        void _wxFB_OnClose( wxCloseEvent& event ){ OnClose( event ); }
        void _wxFB_OnQuit( wxCommandEvent& event ){ OnQuit( event ); }
        void _wxFB_OnAbout( wxCommandEvent& event ){ OnAbout( event ); }
        
    
    protected:
        wxMenuBar* mbar;
        wxStatusBar* statusBar;
        
        // Virtual event handlers, overide them in your derived class
        virtual void OnClose( wxCloseEvent& event ){ event.Skip(); }
        virtual void OnQuit( wxCommandEvent& event ){ event.Skip(); }
        virtual void OnAbout( wxCommandEvent& event ){ event.Skip(); }
        
    
    public:
        GUIFrame( wxWindow* parent, int id = wxID_ANY, wxString title = wxT("wxWidgets Application Template"), wxPoint pos = wxDefaultPosition, wxSize size = wxSize( 481,466 ), int style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
    
};

#endif //__GUIFrame__
5. testApp.h

Code: Select all

/***************************************************************
 * Name:      testApp.h
 * Purpose:   Defines Application Class
 * Author:    FR ()
 * Created:   2022-12-03
 * Copyright: FR ()
 * License:
 **************************************************************/

#ifndef TESTAPP_H
#define TESTAPP_H

#include <wx/app.h>

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

#endif // TESTAPP_H
6. testMain.h

Code: Select all

/***************************************************************
 * Name:      testMain.h
 * Purpose:   Defines Application Frame
 * Author:    FR ()
 * Created:   2022-12-03
 * Copyright: FR ()
 * License:
 **************************************************************/

#ifndef TESTMAIN_H
#define TESTMAIN_H



#include "testApp.h"


#include "GUIFrame.h"

class testFrame: public GUIFrame
{
    public:
        testFrame(wxFrame *frame);
        ~testFrame();
    private:
        virtual void OnClose(wxCloseEvent& event);
        virtual void OnQuit(wxCommandEvent& event);
        virtual void OnAbout(wxCommandEvent& event);
};

#endif // TESTMAIN_H
EDIT:
All the code above was not produced or changed by me. Every single line has been produced by the C::B wizard PBs has provided.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: PB’s Guide to Starting with wxWidgets on Microsoft Windows with MinGW and Code::Blocks

Post by ONEEYEMAN »

Hi,
There are a lot of code on the web that was made by the old version of wxwidgets, some even with 2.4 and it was never updated to the newer version.

However, this is not the case here. Thx for clarifying.

And you got those warnings building the project and NOT wxWidgets itself, right? What exact command you used to build wxWidgets?

Thank you.
FrankR
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri Dec 02, 2022 9:58 am

Re: PB’s Guide to Starting with wxWidgets on Microsoft Windows with MinGW and Code::Blocks

Post by FrankR »

ONEEYEMAN wrote: Sun Dec 04, 2022 6:16 pm And you got those warnings building the project and NOT wxWidgets itself, right? What exact command you used to build wxWidgets?
Yes, I get those warnings building the project, NOT wxWidgets.
ONEEYEMAN wrote: Sun Dec 04, 2022 6:16 pm What exact command you used to build wxWidgets?
I used the following batchfile:

Code: Select all

REM This batch file is a part of PB’s Guide to Starting with wxWidgets on Microsoft Windows with MinGW and Code::Blocks 

set PATH=C:\msys64\mingw64\bin;%PATH%

cd /d %WXWIN%\build\MSW


REM Build wxWidgets Shared Debug configuration with C++17 support
mingw32-make -f makefile.gcc SHARED=1 BUILD=debug CXXFLAGS="-std=c++17" SHELL=cmd.exe setup_h
IF %ERRORLEVEL% NEQ 0 goto FAIL
mingw32-make -j2 -f makefile.gcc SHARED=1 BUILD=debug CXXFLAGS="-std=c++17" SHELL=cmd.exe
IF %ERRORLEVEL% NEQ 0 goto FAIL

REM Build wxWidgets Shared Release configuration with C++17 support
mingw32-make -f makefile.gcc SHARED=1 BUILD=release CXXFLAGS="-std=c++17" SHELL=cmd.exe setup_h
IF %ERRORLEVEL% NEQ 0 goto FAIL
mingw32-make -j2 -f makefile.gcc SHARED=1 BUILD=release CXXFLAGS="-std=c++17" SHELL=cmd.exe
IF %ERRORLEVEL% NEQ 0 goto FAIL


goto SUCCESS

:FAIL
echo Build failed, see above why.
pause
goto FINISHED

:SUCCESS

:FINISHED
I did not watch those 2 build jobs. Therefore I can't say if something went wrong.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: PB’s Guide to Starting with wxWidgets on Microsoft Windows with MinGW and Code::Blocks

Post by ONEEYEMAN »

Hi,
Just to make sure, do this:

Code: Select all

cd wxwidgets\samples\minimal
mingw32-make -f makefile.gcc SHARED=1 BUILD=debug  CXXFLAGS="-std=c++17" SHELL=cmd.exe
.\minimal.exe
Thank you.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: PB’s Guide to Starting with wxWidgets on Microsoft Windows with MinGW and Code::Blocks

Post by PB »

Firstly, I do agree that the warnings are annoying, I certainly did not like getting those wxFont ctor warning when using older wxFormBuilder back then. But they do have a purpose, i.e., to make you stop using code that may be error-prone and is going to be removed sooner or later.

Secondly, the updated wizard I provide along my guide does not produce any C++ code. It shows the wizard dialog and sets the project settings. The C++ code is provided by the Code::Blocks template, which can be found in the C::B install folder (e.g., C:\Program Files\CodeBlocks\) in folder share\CodeBlocks\templates\wizard\wxwidgets and I did not modify it in any way.

Secondly, there are no deprecation warnings for the program generated by the wizard as described in my guide:
------------- Build: Debug in Test321b (compiler: msys2-mingw-w64-x86_64)---------------

windres.exe -ID:\Dev\Desktop\!Lib\wxWidgets-3.2.1\include -ID:\Dev\Desktop\!Lib\wxWidgets-3.2.1\lib\gcc_dll-x64\mswud -J rc -O coff -i C:\dev\cb-tests\Test321b\resource.rc -o obj\Debug\resource.res
g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -Wall -g -D__WXDEBUG__ -ID:\Dev\Desktop\!Lib\wxWidgets-3.2.1\include -ID:\Dev\Desktop\!Lib\wxWidgets-3.2.1\lib\gcc_dll-x64\mswud -c C:\dev\cb-tests\Test321b\Test321bApp.cpp -o obj\Debug\Test321bApp.o
g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -Wall -g -D__WXDEBUG__ -ID:\Dev\Desktop\!Lib\wxWidgets-3.2.1\include -ID:\Dev\Desktop\!Lib\wxWidgets-3.2.1\lib\gcc_dll-x64\mswud -c C:\dev\cb-tests\Test321b\Test321bMain.cpp -o obj\Debug\Test321bMain.o
g++.exe -LD:\Dev\Desktop\!Lib\wxWidgets-3.2.1\lib\gcc_dll-x64 -o bin\Debug\Test321b.exe obj\Debug\Test321bApp.o obj\Debug\Test321bMain.o obj\Debug\resource.res -mthreads -lwxmsw32ud_webview -lwxmsw32ud_stc -lwxmsw32ud_propgrid -lwxmsw32ud_ribbon -lwxmsw32ud_richtext -lwxmsw32ud_xrc -lwxmsw32ud_aui -lwxmsw32ud_media -lwxbase32ud_net -lwxmsw32ud_gl -lwxbase32ud_xml -lwxmsw32ud_adv -lwxmsw32ud_html -lwxmsw32ud_core -lwxbase32ud -mwindows
Output file is bin\Debug\Test321b.exe with size 907.71 KB
Process terminated with status 0 (0 minute(s), 4 second(s))
0 error(s), 0 warning(s) (0 minute(s), 4 second(s))
This is hardly surprising, as the generated code does not use the deprecated wxFont constructor nor does it attempt to create a wxTimerEvent instance. But neither does your code posted above, so I have no idea where your warnings come from.

Thirdly, I would not be surprised if wxSmith did generate outdated code. AFAIK, the plugin is not maintained much and may even lack support for newer wxWidgets classes (such as ribbon, webview, stc, or propgrid). I myself never used it, I use wxFormBuilder. However, I tried changing the font for a button and wxSmith did generate the correct ctor.

EDIT
Sorry, I only now realized that you did not use wxSmith (used by default in the guide) but chose wxFormBuilder so my wxSmith comments are irrelevant. The rest still stands though.
FrankR
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri Dec 02, 2022 9:58 am

Re: PB’s Guide to Starting with wxWidgets on Microsoft Windows with MinGW and Code::Blocks

Post by FrankR »

ONEEYEMAN wrote: Sun Dec 04, 2022 7:54 pm Hi,
Just to make sure, do this:

Code: Select all

cd wxwidgets\samples\minimal
mingw32-make -f makefile.gcc SHARED=1 BUILD=debug  CXXFLAGS="-std=c++17" SHELL=cmd.exe
.\minimal.exe
Thank you.
I did. There were no warnings and after copying the libs named by figure 3-8 in PBs Guide minimal.exe is up and running.
FrankR
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri Dec 02, 2022 9:58 am

Re: PB’s Guide to Starting with wxWidgets on Microsoft Windows with MinGW and Code::Blocks

Post by FrankR »

PB wrote: Sun Dec 04, 2022 7:54 pm But they do have a purpose, i.e., to make you stop using code that may be error-prone and is going to be removed sooner or later.
I (hopefully!) did not say that I want to suppress the warnings. My aim is to get rid of them by locating the code that causes these warnings and to replace it with a piece of code that does not use deprecated features. So we are on the same wave-length I guess.
PB wrote: Sun Dec 04, 2022 7:54 pm Secondly, the updated wizard I provide along my guide does not produce any C++ code. It shows the wizard dialog and sets the project settings. The C++ code is provided by the Code::Blocks template, which can be found in the C::B install folder (e.g., C:\Program Files\CodeBlocks\) in folder share\CodeBlocks\templates\wizard\wxwidgets and I did not modify it in any way.
OK, that's an important information for me. I will have a look into that folder. Thanks!
PB wrote: Sun Dec 04, 2022 7:54 pm Thirdly, I would not be surprised if wxSmith did generate outdated code. AFAIK, the plugin is not maintained much and may even lack support for newer wxWidgets classes (such as ribbon, webview, stc, or propgrid). I myself never used it, I use wxFormBuilder. However, I tried changing the font for a button and wxSmith did generate the correct ctor.

EDIT
Sorry, I only now realized that you did not use wxSmith (used by default in the guide) but chose wxFormBuilder so my wxSmith comments are irrelevant. The rest still stands though.
Sorry, my mistake! I used wxSmith like described in your guide in my first attempt but posted the code from my second attempt. The second one was using GUIFrame.cpp.

Last night I made a fresh build of wxWidgets 3.2.1 in a new folder and changed %WXWIN% to the new path. I made two tests, one using wxSmith the other wxFormBuilder. Both produce the same warnings regarding wxFonts.

Thanks to your hint I was able to locate the code snippet causing the warnings. There is one in line 120 within C:\Program Files\CodeBlocks\share\CodeBlocks\templates\wizard\wxwidgets\common\main.cpp

Code: Select all

m_staticText1->SetFont(wxFont(20, 74, 90, 90, false, wxT("Arial")));
and another in line 35 within C:\Program Files\CodeBlocks\share\CodeBlocks\templates\wizard\wxwidgets\wxfb\dialog\GUIDialog.cpp

Code: Select all

m_staticText1->SetFont( wxFont( 20, 74, 90, 90, false, wxT("Arial") ) );
Is there a newer version of this widget?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: PB’s Guide to Starting with wxWidgets on Microsoft Windows with MinGW and Code::Blocks

Post by ONEEYEMAN »

Hi,
Do you have a latest version of C::B?

Thank you.
FrankR
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri Dec 02, 2022 9:58 am

Re: PB’s Guide to Starting with wxWidgets on Microsoft Windows with MinGW and Code::Blocks

Post by FrankR »

Yes, according to the guide I downloaded "codeblocks-20.03-setup.exe"
FrankR
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri Dec 02, 2022 9:58 am

Re: PB’s Guide to Starting with wxWidgets on Microsoft Windows with MinGW and Code::Blocks

Post by FrankR »

MY FAULT!!!

I installed C::B 20.03 on a new machine and now all warnings are gone.

My other machine had C::B 17 installed and though I uninstalled everything before installing v20.03 there must have been some remainders from that old version. SORRY!
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: PB’s Guide to Starting with wxWidgets on Microsoft Windows with MinGW and Code::Blocks

Post by PB »

Actually, the warnings still can be there with C::B 20.03 template at least when one uses (a) dialog-based application and (b) wxFormBuilder.

The template should be updated but TBH, the offending code is going to be removed in an actual application, so...
FrankR
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri Dec 02, 2022 9:58 am

Re: PB’s Guide to Starting with wxWidgets on Microsoft Windows with MinGW and Code::Blocks

Post by FrankR »

Thanks for all your help!
kmutiny
In need of some credit
In need of some credit
Posts: 3
Joined: Thu May 06, 2021 8:20 pm

Re: PB’s Guide to Starting with wxWidgets on Microsoft Windows with MinGW and Code::Blocks

Post by kmutiny »

Universal batch file

Thanks PB. This guide was a great help.

I followed the guide, and succeeded in compiling several of the samples by using PB’s bat file with slight mods (SHARED=0) in each of the sample folders.

So it’s working.

Then I tried this:

I copied the sample folder to my desktop, and ran the bat for minimal.cpp, and it failed.

minimal.cpp:20:10: fatal error: wx/wxprec.h: No such file or directory
20 | #include "wx/wxprec.h"
| ^~~~~~~~~~~~~
compilation terminated.
mingw32-make: *** [gcc_mswu\minimal_minimal.o] Error 1

How can I make this work?

This batch file would be ideal if it could work for more than just the samples but for the most general projects.

You just put it in the folder with your code and run it.

Any thoughts?

Thanks
Post Reply