Skip to main content

How to use wxWidgets on Windows with a Makefile

 Hello!

I wanted to learn GUI rpogramming in C++. One of the main libraries for this purpose is called wxWidgets. It's very popular and seem powerful enough to make even a complex graphical interface. I also liked the fact that it's multi platforms.

I am on Windows, using MingW and I like coding with VS Code. I also like having a clear Makefile to generate my programs. So here is how I have managed to compile the Hello World program you can find on the wxWidgets website.

First, go to their github repository and clone it in a folder you will keep on your computer.

In the root directory, run the command git submodule update --init. If the clone operation has not done so already, this command will pull additional repositories needed by wxWidget.

Go to build\msw.

Run the command: mingw32-make -f makefile.gcc -j4 SHARED=1 UNICODE=1 BUILD=debug clean.

It will delete any unwanted file.

Once it's done, re run the command but without the clean instruction. This will build the library from the source. This way you can control exactly which version you want.

During the build process, I got some errors regarding c:\mingw\lib\bfd-plugins\libdep.a. As far as I understood the bug reports on this error, it will not affect the resulting build. In my case, it did not prevent the Hello World program from running. I am not sure if more advanced features will be an issue because of it. Anyway, in the context of this article, just click the ok button to dismiss the error.

It will take a little while. Like, around 15 minutes.

Once it's done, you should find inside of the git repository:

An include folder, which contains the header files.

A lib folder, which contains the library files and the dll.

Alright, now, we have all we need, and it's just a matter of linking the correct folders in the Makefile. 

For the includes, you will need: 

  • -IC:\path_to_git_repo\include
  • -IC:\path_to_git_repo\lib\gcc_dll\mswud (this one is because there is a setup.h inside)

For the linkers, you will need:

  • -LC:\path_to_git_repo\lib\gcc_dll
  • -lwxmsw31ud_core -lwxbase31ud

Copy the corresponding dlls in the folder where your Makefile will generate your executable. The dlls names are: 

  • wxbase316ud_gcc_custom 
  • wxmsw316ud_core_gcc_custom

And that's it! You can now compile your program like you would normally.

Now, notice the BUILD=debug argument when we built from the source? Before sharing your GUI application with the whole world, you want to use the release version of wxWidget. To do so, you have to rebuild it by replacing BUILD=debug by BUILD=release. Once it is done, you have to include/link the same file names but without the letter d at the end (so, mswu instead of mswud,  -lwxmsw31u_core instead of -lwxmsw31ud_core, etc.). The build time is even longer for the release version.

I hope it was helpful,

Have fun!

 

Comments

Popular posts from this blog

Windows 11, bootable USB device not detected

 I recently needed to install a linux server on a new computer. The current operating system was windows 11. I decided to go with Ubuntu server. After following their instructions on how to download and create an .ISO image with Rufus , I had a problem: my USB key was not detected by the new computer as a bootable key. It turned our that the solution was the USB version. My USB key was 2.0. After doing exactly the same operation on a USB 3.0 device, everything worked fine. Bonus tip: on windows, to boot from a device, it's possible to restart the computer while holding the SHIFT key. The computer will restart and then display a menu from which you can access the different ways of booting your system. This menu will include any bootable device. Hope it helps!

Installing Postgres on Linux Lite (Ubuntu)

I have followed these instructions from the Postgres documentation : # Create the file repository configuration: sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' # Import the repository signing key: wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - # Update the package lists: sudo apt-get update # Install the latest version of PostgreSQL. # If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql': sudo apt-get -y install postgresql   After that, I was having trouble authenticating to Postgresql after installing the db server on Linux Lite.  This stackoverflow answer was very helpful. Open the file pg_hba.conf . For Ubuntu, use for example /etc/postgresql/13/main$ sudo nano pg_hba.conf and change this line at the bottom of the file, it should be the first line of the settings: local all ...