Using wxWidgets with Win10, msys2, mingw64 and CLion

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
Zimon
In need of some credit
In need of some credit
Posts: 1
Joined: Fri Sep 25, 2020 10:19 am

Using wxWidgets with Win10, msys2, mingw64 and CLion

Post by Zimon »

Hello,

I am starting to learn how to use wxWidgets and after 3 days am not even able to get it to work using my regular C++ environment. I've read many tutorials, but none of them seem to cover the specific combination of MSYS2, MingW and CLion. My goal is to build an run the HelloWorld App for starters.

Let me list what i've tried:
  • installing the MingW packages "mingw-w64-x86_64-wxWidgets" and "mingw-w64-i686-wxWidgets".
  • manually compile the github packages and installing the libs to MingW
  • using the prebuilt development libraries für MingW (this appeared to be the most promising approach, since I was able to start the compiling process but got loads of errors relating to missing constants of the setup.h, which I still struggle to understand the purpose of).
  • downloading the Linux and Windows versions from the website (what's the difference compared to the github version and which one would I need for the MSYS2, which is a Linux-type system)?
I've read that I am merely to build and install the libs for wxWidgets, but apparently that's not quite the case. I am suprised how different wokring with wx is compared to Qt5, which only needs the packages that are available as part of the msys2/MingW repo.

Sorry for those questions, but after 3 days of trying to get this to work, I can honestly say, that no online source to far really helped me with this and I really would like to try out wxWidgets.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post by doublemax »

Maybe you should start with the standard: Building wxWidgets and then the "minimal" sample that comes with wxWidgets, with MinGW. This is all well documented in <wxdir>/docs/msw/install.md and e.g. viewtopic.php?f=19&t=47231 (Although this uses CodeBlocks, the first part, just building wxWidgets is the same).

If you run into problems, post what you did and the exact error message you get.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

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

Post by ONEEYEMAN »

Hi,
Hello,
Zimon wrote: Fri Sep 25, 2020 10:37 am I am starting to learn how to use wxWidgets and after 3 days am not even able to get it to work using my regular C++ environment. I've read many tutorials, but none of them seem to cover the specific combination of MSYS2, MingW and CLion. My goal is to build an run the HelloWorld App for starters.
Welcome!
Zimon wrote: Fri Sep 25, 2020 10:37 am Let me list what i've tried:
  • installing the MingW packages "mingw-w64-x86_64-wxWidgets" and "mingw-w64-i686-wxWidgets".
Let me stop you right there.
When you say "installing wxWidgets" - what did you mean?
Downloaded and run the installer?
Downloaded prebuilt binaries from wxwidgets.org/download?
Installed prebuilt binaries from the MSYS environment??
Something else?
Zimon wrote: Fri Sep 25, 2020 10:37 am
  • manually compile the github packages and installing the libs to MingW
Did you compile them using standard MSYS way - using configure?
Or you are working from the Windows environment with just MinGW?
Zimon wrote: Fri Sep 25, 2020 10:37 am
  • using the prebuilt development libraries für MingW (this appeared to be the most promising approach, since I was able to start the compiling process but got loads of errors relating to missing constants of the setup.h, which I still struggle to understand the purpose of).
What you were tried to compile? How? Inside MSYS or Windows environment? What command did you use?
Zimon wrote: Fri Sep 25, 2020 10:37 am
  • downloading the Linux and Windows versions from the website (what's the difference compared to the github version and which one would I need for the MSYS2, which is a Linux-type system)?
Please do not mix up different OSes - start with one and then move to the other one.
For the MSYS you will need the Windows source code.
Zimon wrote: Fri Sep 25, 2020 10:37 am I've read that I am merely to build and install the libs for wxWidgets, but apparently that's not quite the case. I am suprised how different wokring with wx is compared to Qt5, which only needs the packages that are available as part of the msys2/MingW repo.
I believe there is a package made for MSYS environment and you can catch its "maintainer" here on the forum.
However, it is very easy to build wxWidgets for MSYS{2} -- do the following:

Code: Select all

cd wxWidgets
mkdir buildMSYS
cd buildMSYS
CXXFLAGS="-std=c++11" ..configure --with-msw --enable-debug && make
make install
Now, the only difference between Windows and Linux/Mac versions is the line ending,
But for MSYS2 getting the Windows archive is better.
Zimon wrote: Fri Sep 25, 2020 10:37 am Sorry for those questions, but after 3 days of trying to get this to work, I can honestly say, that no online source to far really helped me with this and I really would like to try out wxWidgets.
Please let us know if you get any other questions - we are here to help.

Thank you.
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 548
Joined: Fri Nov 03, 2006 2:00 pm

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

Post by stahta01 »

Word of warning trying to use the wx-config from the MSys2 MinGW32/64 wxWidgets 3.0.5.1 or 3.1.3 package is not easy to do unless it is ran from inside the Msys2 sh.exe.

I have no idea how Clion IDE finds the location of wxWidgets; without this info I have no idea if the OP should try using the MSys2 wxWidgets packages or not. Or if the OP needs to build the wxWidgets binaries for themselves.

Tim S.
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 548
Joined: Fri Nov 03, 2006 2:00 pm

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

Post by stahta01 »

I have downloaded an 30 day trial copy of Clion; I am on Windows 7 64 bit.

I will see if I can build the wxWidgets CMake minimal sample; could be hours or days before I make much progress.

Links I plan to use as reference
https://www.jetbrains.com/help/clion/qu ... ndows.html
viewtopic.php?t=45198

CLion with MSYS2 https://gist.github.com/phazmatis/fd747 ... 7da49baacb
CLion with MSYS2 and Qt https://blog.bachi.net/?p=9485
Embedding MSYS2 terminal in CLion https://menaceinc.com/2019/03/embedding-msys2-in-clion/

Tim S.
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 548
Joined: Fri Nov 03, 2006 2:00 pm

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

Post by stahta01 »

I have decide to remove Clion from the problem.

So, I will first try to get MSys2, MinGW64 GCC, CMake, and wxWidgets to work together.

Tim S.
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 548
Joined: Fri Nov 03, 2006 2:00 pm

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

Post by stahta01 »

I have gotten minimal to build under Clion.

The below line is for use with normal "mingw32-make -f makefile.gcc" built wxWidgets

Code: Select all

-DwxWidgets_FIND_STYLE:STRING="win32" -DwxWidgets_ROOT_DIR:STRING="C:/repos/git/wxWidgets" -DwxWidgets_LIB_DIR:STRING="C:/repos/git/wxWidgets/lib/gcc_dll" -DwxWidgets_CONFIGURATION="mswu"
The above had to be added to "Cmake Options"
I found this setting under File -> Settings
Build, Execution, Deployment -> cmake

It built OK; but, it had run-time errors likely missing DLLs from run-time path.

Edit: I built wxWidgets git master branch shared libs; I am now building git master branch static libs to see if the run-time error goes away.

Tim S.
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 548
Joined: Fri Nov 03, 2006 2:00 pm

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

Post by stahta01 »

Check disk found no problems after last night major problem (Hard drive space was exhausted)

Static wxWidgets libraries built and sample built and ran with no problem

Code: Select all

-DwxWidgets_FIND_STYLE:STRING="win32" -DwxWidgets_ROOT_DIR:STRING="C:/repos/git/wxWidgets" -DwxWidgets_LIB_DIR:STRING="C:/repos/git/wxWidgets/lib/gcc_lib" -DwxWidgets_CONFIGURATION="mswu"
Complete rebuild log

Code: Select all

====================[ Clean | Release ]=========================================
"C:\Program Files\JetBrains\CLion 2020.2.3\bin\cmake\win\bin\cmake.exe" --build C:\repos\git\wxWidgets\samples\minimal\cmake-build-release --target clean -- -j 1

Clean finished

====================[ Build | all | Release ]===================================
"C:\Program Files\JetBrains\CLion 2020.2.3\bin\cmake\win\bin\cmake.exe" --build C:\repos\git\wxWidgets\samples\minimal\cmake-build-release --target all -- -j 1
[ 33%] Building CXX object CMakeFiles/minimal.dir/minimal.cpp.obj
[ 66%] Building RC object CMakeFiles/minimal.dir/C_/repos/git/wxWidgets/samples/sample.rc.obj
[100%] Linking CXX executable minimal.exe
[100%] Built target minimal

Build finished
Run log

Code: Select all

C:\repos\git\wxWidgets\samples\minimal\cmake-build-release\minimal.exe

Process finished with exit code 0

Tim S.
stahta01
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 548
Joined: Fri Nov 03, 2006 2:00 pm

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

Post by stahta01 »

Since, I got an CLion minimal static wxWidgets built using makefile.gcc to build and run without error; I have uninstalled CLion.

Tim S.
ollydbg23
Super wx Problem Solver
Super wx Problem Solver
Posts: 438
Joined: Fri Dec 12, 2008 10:31 am

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

Post by ollydbg23 »

Hi, tim.

I see in your recent posts, you use the MSYS2's MinGW-w64 compiler to build the wxWidgets library, and later use this library.

What I see the problem is:

MSYS2 already have prebuild wx library, I see currently, there are libraries for wx 3.0.5 and wx 3.1.3, so I can use pacman to install those libraries very easy.

The problem here is: the MSYS2 prebuild wx library seems have <msys2-root>\mingw64\bin\wx-config or <msys2-root>\mingw64\bin\wx-config-3.1, but those two files are bash script files(the prebuild wx library is build from the MSYS2 shell's make command, not the mingw32-make.exe), when I try to run cmake from the normal Windows command line, they failed to find the wx library.

The only way is specify the -G "MSYS Makefiles" option to the cmake command line option, so that those bash script files will be used by the cmake, but the bad thing is the generated makefile is a MSYS/UNIX style, and can't be run under mingw32-make.exe(which is used in either Code::Blocks or CodeLite and many IDEs)

I'm not sure a windows native wx-config.exe could solve this issue, and can find the MSYS2's prebuild wx library correctly.

Thanks.
ollydbg23
Super wx Problem Solver
Super wx Problem Solver
Posts: 438
Joined: Fri Dec 12, 2008 10:31 am

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

Post by ollydbg23 »

This is the way to hack the cmake, and make usage of wx library supplied by msys2 under mingw32-make.exe.

Suppose you have cmake install by pacman (mingw64/mingw-w64-x86_64-cmake 3.17.3-1):

Code: Select all

$ which cmake
/mingw64/bin/cmake
Suppose you have wxWidgets installed by pacman (mingw64/mingw-w64-x86_64-wxWidgets 3.0.5.1-1)


Here is the hack, you have to change two liens in the below file:
<msys2_root>\mingw64\share\cmake-3.17\Modules\FindwxWidgets.cmake

change the line 212 to

Code: Select all

if(WIN32 AND NOT CYGWIN AND NOT MSYS AND NOT MINGW AND NOT CMAKE_CROSSCOMPILING)
change the line 884 to

Code: Select all

if(wxWidgets_FOUND AND (MSYS OR MINGW))
Then, in your CMakeLists.txt

Code: Select all

find_package(wxWidgets 3.0.5 COMPONENTS core base REQUIRED)
Then run the command inside the mingw64.exe shell (which locates <msys2_root>\mingw64.exe)

Code: Select all

cmake .. -G "MinGW Makefiles"
Then the generated makefile can be used by mingw32-make.exe
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

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

Post by ONEEYEMAN »

Hi,
You are using MSYS - what is wrong with using configure and make to build the library?

Using "cmake" you repeating the work wxWidgets team already did for you.

Thank you.
ollydbg23
Super wx Problem Solver
Super wx Problem Solver
Posts: 438
Joined: Fri Dec 12, 2008 10:31 am

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

Post by ollydbg23 »

Hi, guys, some news about using cmake when you would like to link to the wx libs from msys2.

I have a new post here: MSYS2: using the cmake to created a wxWidgets application

Hope that can help other guys.
Post Reply