'Include wxWidgets (3.1.1) installed with msys 2 into our project, using cmake

We are trying to include and make wxWidgets run in our project. We are using CMake to compile and to include our libraries with msys2. We are using CLion as IDE. After several days of testing, we are still unable to make it run. There are way too many and different errors to post all of them. I think we have tried everything you can possible do, read everything you can possible read, but it still won't work.

We also tried to install the whole wxWidget.zip Folder and implement everything by path, still nothing.

There are some posts about this issue, but nothing seems to work.

My question, is there anybody who encountered the same problem and fixed that? Is there a step by step guide to implement everything correctly?

Thanks in advance!



Solution 1:[1]

Since the current msys2 version of wxwidgets does not work correctly (FindCMake file not working + different folder names for include than in the docs on the wxWidgets homepage), I suggest the following workaround:

  1. Download wxWidgets and unpack it to a directory of your choice.
  2. Run CLion (and build wxWidgets the following way):
    • Close any open project and do Import Projetct from Sources.
    • Select the directory you unzipped wxWidgets into.
    • Select Use existing CMakeLists.txt
    • After CMake finished loading - Build the project (Ctrl + F9). I recommend using release mode.
  3. After building wxWidgets finished in CLion, there is a new folder called 'cmake-build-release' or 'cmake-build-debug'. If you would like to integrate the wxWidgets built into your project, I suggest:
    • copy all .a-files from /lib/gcc_dll/ to a new project folder,
    • copy all .dll files from /lib/gcc_dll/ to your project build folder
    • copy the include folder from the original wxWidgets archive to your project and in any case copy the setup.h from /lib/gcc_dll/mswud/wx/ to the include folder as well.
  4. Edit your project's CMakeLists.txt:
    • To your include_directories add the path to the wxWidgets include folder
    • To your target_link_libraries add the path of every .a file.

In my case point 4 resulted in the following lines to make it crystal clear:

include_directories(
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_headers/include
        )

and

target_link_libraries(example_project
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxbase31u.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxbase31u_net.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxbase31u_xml.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxexpat.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxjpeg.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxmsw31u_adv.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxmsw31u_aui.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxmsw31u_core.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxmsw31u_gl.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxmsw31u_html.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxmsw31u_media.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxmsw31u_propgrid.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxmsw31u_qa.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxmsw31u_ribbon.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxmsw31u_richtext.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxmsw31u_stc.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxmsw31u_webview.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxmsw31u_xrc.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxpng.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxregexu.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxscintilla.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxtiff.a
        ${CMAKE_CURRENT_SOURCE_DIR}/cpp/libs/wx_build/libwxzlib.a
)

DISCLAIMER:

You should know, that including libraries that way is considered bad practise and as soon as MSYS2 supplies a wxWidgets library with a working find_package-file use that instead!

Solution 2:[2]

The core problem is the wx library installed by pacman in msys2 is build from "make", which is a unix like shell, which has different folder structure compared with the native windows mingw build wx.

Under Msys2, to generate the mingw style makefile from cmake, you have to hack the cmake file: <msys2_root>\mingw64\share\cmake-3.17\Modules\FindwxWidgets.cmake

Here is the detail:

Re: Using wxWidgets with Win10, msys2, mingw64 and CLion

After that, you can correctly use the mingw style makefile.

EDIT 2022-04-30, msys2's cmake now can correctly find wx library, see my tutorials here:

https://github.com/msys2/MINGW-packages/issues/11585#issuecomment-1113904778

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Developer Guy
Solution 2