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.
Post Reply
PB
Part Of The Furniture
Part Of The Furniture
Posts: 2677
Joined: Sun Jan 03, 2010 5:45 pm

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

Post by PB » Thu Jun 04, 2020 7:11 pm

I am aware that there already are several recent guides to using wxWidgets with MinGW and Code::Blocks. However, I wrote most of mine almost two years ago, but did not find time to finish it. But now I did and updated it for the latest versions of wxWidgets, MinGW and Code::Blocks.

My guide hopes to assist the readers with decisions regarding which wxWidgets version and configuration to use and show how to build wxWidgets using MinGW with various parameters affecting the resulting build. It also describes in detail setting-up a wxWidgets project in popular IDE Code::Blocks. Its page count may seem off-putting to some, but there is not that much text, most of it is pictures and whitespace.

I wrote the guide in Microsoft Word, using complex formatting and it seems that converting all of it to MediaWiki or HTML format is quite difficult, so at least for the time being, it is provided only in the PDF format.

The guide is available at https://github.com/PBfordev/wxpbguide as wxPBGuide.pdf. I recommend using a decent PDF viewer instead of GitHub's built-in one, which lacks useful features such as displaying a navigable TOC or clicking on document's internal cross links.

Perhaps the guide helps someone, it should cover all necessary information, hopefully presented in a simple and understandable way.

Versions of software used in guide
wxWidgets: 3.1.4
MinGW: MSYS2 mingw-w64-i686-toolchain (GCC 10.2 at the time of writing)
Code::Blocks: 20.03

Table of Contents
----------
1 Introduction
2 Basic wxWidgets Information
2.1 wxWidgets Versions
2.2 Shared vs Static Linking
2.3 Multilib vs Monolithic Build
2.4 Debug and Release Configuration
2.5 32-bit vs 64-bit Build
2.6 To Build or Not to Build
3 Building wxWidgets with MinGW
3.1 Choosing MinGW Distribution
3.2 Installing MSYS2
3.3 Installing MSYS2 packages for developing C++ applications
3.4 Downloading wxWidgets Sources
3.5 Adding System Environment Variable WXWIN
3.6 The Build
3.6.1 Starting Simple
3.6.2 Improving Build Commands
3.6.3 Making wxWidgets Build Faster
3.6.4 Viewing Build Results
3.6.5 Using the Minimal Sample to Test the Build
3.6.6 Cleaning the Build
3.6.7 Building wxWidgets Statically
3.6.8 More Build Options
4 Setting Up wxWidgets Project with Code::Blocks and MinGW
4.1 Installing Code::Blocks
4.2 Configuring the Debugger
4.3 Configuring the Compiler
4.4 Creating Global Variable wx
4.5 Creating a wxWidgets Project with Project Wizard
4.5.1 Selecting wxWidgets Project Template
4.5.2 Wizard Page 1: Welcome
4.5.3 Wizard Page 2: wxWidgets Version
4.5.4 Wizard Page 3: Project Title and Paths
4.5.5 Wizard Page 4: Project Author
4.5.6 Wizard Page 5: GUI Builder and Application Type
4.5.7 Wizard Page 6: wxWidgets Location
4.5.8 Wizard Page 7: Compiler and Debug/Release Configurations
4.5.9 Wizard Page 8: Various Configuration Options
4.5.10 Wizard Page 9: Advanced Options
4.5.11 Wizard Page 10: Additional Libraries
4.6 Adjusting Project Settings
4.6.1 Setting C++ Standard Used in the Project
4.6.2 Setting Preprocessor Define NDEBUG for the Release Build Target
4.6.3 Making the Application DPI-Aware
4.6.4 Setting Other Project Options
4.7 Finally Finished!
4.8 Extra Reading: wxWidgets Code::Blocks Project Under the Hood
4.8.1 Compiler Include Folders
4.8.2 Preprocessor Defines
4.8.3 Linker Settings
4.8.4 Using Static Instead of Shared wxWidgets Build
Last edited by PB on Wed Oct 28, 2020 3:43 pm, edited 2 times in total.

tuk1
Experienced Solver
Experienced Solver
Posts: 95
Joined: Sun Oct 08, 2017 9:36 am

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

Post by tuk1 » Sun Sep 20, 2020 2:23 pm

Not sure if youre inviting replies here and couldnt find a way to pm.

Using wx 3.1.4 and gcc 10.2.0
All went ok until the build step, tried the commands for dynamic and static, but both failed at the end:
C:\Users\TP1\Desktop\CODE BLOCKS\wxWidgets-3.1.4\build\msw>IF %ERRORLEVEL% NEQ 0 goto FAIL

C:\Users\TP1\Desktop\CODE BLOCKS\wxWidgets-3.1.4\build\msw>goto SUCCESS

C:\Users\TP1\Desktop\CODE BLOCKS\wxWidgets-3.1.4\build\msw>:FAIL
C:\Users\TP1\Desktop\CODE BLOCKS\wxWidgets-3.1.4\build\msw>echo Build failed!
Build failed!

C:\Users\TP1\Desktop\CODE BLOCKS\wxWidgets-3.1.4\build\msw>pause
Press any key to continue . . .
set PATH=c:\msys64\mingw32\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"
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"
IF %ERRORLEVEL% NEQ 0 goto FAIL
goto SUCCESS
:FAIL
echo Build failed!
pause
goto FINISHED
:SUCCESS
:FINISHED
and..
set PATH=c:\msys64\mingw32\bin;%PATH%
cd /d %WXWIN%\build\MSW
REM Build wxWidgets Static Debug configuration with C++17 support and GCC libraries linked statically
mingw32-make -f makefile.gcc SHARED=0 BUILD=debug CXXFLAGS="-std=c++17" LDFLAGS="-static"
IF %ERRORLEVEL% NEQ 0 goto FAIL
REM Build wxWidgets Static Release configuration with C++17 support and GCC libraries linked statically
mingw32-make -f makefile.gcc SHARED=0 BUILD=release CXXFLAGS="-std=c++17" LDFLAGS="-static"
IF %ERRORLEVEL% NEQ 0 goto FAIL
goto SUCCESS
:FAIL
echo Build failed!
pause
goto FINISHED
:SUCCESS
:FINISHED
How to troubleshoot?
wxWidgets(v3.1.3) - Vs2019(v142) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2677
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 » Sun Sep 20, 2020 6:05 pm

Did you run those commands as a batch file as stated in the guide, which are also available here?

You should see the actual build output above the "Press any key to continue . . ." line

BTW, if you have CPU with at least 4 cores and an SSD, I strongly suggest you use the "parallel" versions of the bat files, they are much faster.

tuk1
Experienced Solver
Experienced Solver
Posts: 95
Joined: Sun Oct 08, 2017 9:36 am

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

Post by tuk1 » Tue Sep 22, 2020 5:22 am

The batch file did the trick. I guess it didnt like the commands being block pasted into cmd.

One last thing, when I tried to run the project at the end, I got some errors:
||=== Build: Debug in Test (compiler: msys2-mingw-w64-i686) ===|
\Program Files\CodeBlocks\MinGW\lib\liboleacc.a||No such file or directory|
\Program Files\CodeBlocks\MinGW\lib\libuxtheme.a||No such file or directory|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 4 second(s)) ===|
I was able to resolve by copying over the 2 missing files as per the OP on this thread:
viewtopic.php?f=19&t=47061

The folders didnt exist("\MinGW\lib\"), I had to create those first before adding the missing files ...any ideas as to the cause, maybe a misstep?
wxWidgets(v3.1.3) - Vs2019(v142) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2677
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 » Tue Sep 22, 2020 6:08 am

No such copying should be ever needed.

The build log indicates that C::B looks for the libraries in its bundled compiler folder instead of the MSYS folder?

You either did not follow my guide or you set something in the global C::B settings that messes with the specific compiler / project settings.

Post Reply