std::mutex missing when building Qt app with MXE gcc - c++

I'm attempting to get a Qt application to build from the command line under linux targetted for windows. I've used mxe to build a toolchain for targetting windows but my build fails whinging about various thread related bits. mxe built with winpthreads and I know the Qt project will build on windows itself from inside of creator, using the pre-packaged mingw compiler. I'm successfully building using my ARM Linux cross compiler, so I just want to get windows done the same. I'm trying to get a one line build on a build server or from Jenkins for all my targets.
I'm guessing I'm missing something that I need to pass to mxe when doing the cross toolchain build or alternatively missing something I need to pass to qmake for this build to succeed.

The issue is with the default MXE build of GCC using win32 threads as opposed to mingws pthreads implementation.
Edit src/gcc.mk and ensure that winpthreads is added to the $(PKG)_DEPS list and then change the configure line so that --enable-threads=win32 becomes --enable-threads=posix.
Then re-make winpthreads and gcc. Note that there is a circular dependency here, you need to build gcc with win32 threads (the default) first THEN remake with winpthreads.
Thanks to Andreia Gaita for this - http://blog.worldofcoding.com/2014/05/cross-compiling-c11-without-going-madder.html

POSIX configuration was added to MXE (Building pthreads inline with gcc and enable optional posix threads in libgcc).
For example, to build qt with that (x64, shared, posix threads):
make MXE_TARGETS='x86_64-w64-mingw32.shared.posix' qt

Related

How to build a Qt C++ application that doesn't need VC Redistributables on a pc to run

I am building an application using Qt C++ and I want it to run on windows computers without having to install VC Redistributables. Apparently when user tries to run the application an error pops that says that VCRUNTIME140.dll is missing.
Build both Qt and your application using compiler option /MT?
https://learn.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=msvc-170
I recommend using GCC (i.e. MinGW) as the compiler. If you do that, your app will generall depend on the msvcrt.dll that comes with Windows and doesn't need to be installed specially (but it depends on exactly how the GCC compiler is configured). It will also possibly depend on some GCC runtime library DLLs that you can just put in the same directory as your EXE.
MSYS2 is a good development environment for using MinGW on Windows: https://msys2.org
I also made a useful set of tools that is capable of cross-compiling statically-linked MinGW/Qt applications from Linux: https://github.com/DavidEGrayson/nixcrpkgs
The Qt applications I build with nixcrpkgs come out as single, standalone EXEs that do not need to be shipped with any DLLs.

Using BOOST_STACKTRACE_USE_BACKTRACE on Windows with MinGW64

I am building a Qt application using Windows and MinGW64. I need to use Boost Stacktrace to generate stack traces like the Linux build of the application already does.
The corresponding switch BOOST_STACKTRACE_USE_BACKTRACE (as described in https://www.boost.org/doc/libs/1_65_1/doc/html/stacktrace/configuration_and_build.html) is set and everything works fine on Linux.
However on Windows the libbacktrace library is missing. The above boost page contains two links to the sources of libbacktrace but I couldn't find a prebuilt binary for Windows/MinGW nor could I find any build instructions or usage documentation for my environment.
How can I use BOOST_STACKTRACE_USE_BACKTRACE with Windows/MinGW64?
I solved this problem (and some more issues) by switching to MSYS2 UCRT. MSYS2 provides a precompiled libbacktrace package.

Make - Internal compiler Error under QT 5.14.2 "Q_CORE_EXPORT"

I just installed QT Creator with QT under Win10 to build an already existing project. (Under Ubuntu everything went fine running the Make file). I'm not an expert for QT therefore I'm not able to find out how to resolve the error:
C:\Qt\5.14.2\mingw73_64\include/QtCore/qfloat16.h:102:54: internal compiler error: in make_rtl_for_nonlocal_decl, at cp/decl.c:6590
Q_CORE_EXPORT static const quint32 mantissatable[];
My gcc version is 8.3.0 (x86_64-posix-seh, Built by strawberryperl.com project). Is there something missing or broken in the installation?
On windows, you generally need to have a Qt which was built with the same (or compatible, but that can be hard to verify) compiler and relevant build options, as what you are using to build your application.
I doubt you will find a pre-built Qt SDK for that version of gcc, so if you want to use it, you should build Qt from sources. It can be a bit tedious on Windows, there are a fewf prerequisites you have to get etc. I recommend you use the Qt online installer to install a MinGW version of Qt SDK, and matching version of MinGW (also offered by the Qt installer.
I just found out from qmake.stash, that the included script for creating the make file always referenced a false path for the gcc compiler. I therefore build i manually with the QT Creator and it worked as expected. So I guess the fault was due to different paths for gcc in the environmental variables.
Here is the bug, there is a link to the patch: https://github.com/msys2/MINGW-packages/issues/5006
Also you can just downgrade to mingw gcc 8.2.0

How can I conditionally include two differently named libraries of the same version for a cross-compile project in Eclipse?

I have an Eclipse project that I want to compile on both Ubuntu and Windows.
I am using boost libraries (specifically asio) which require including the libboost_system...* library. I have compiled boost on both Windows and Ubuntu and ended up with libboost_system_mgw48-mt-1_55.a on Windows and libboost_system.a, libboost_system.so, libboost_system.so.1.55.0 on Ubuntu.
I'm not sure which Ubuntu library I need to include but the bigger issue is how to include both the Windows and Ubuntu library but only on the right OS.
I am using the MinGW toolchain on Windows which by my understanding is more or less GCC? I am then assuming that I should simply use GCC on Ubuntu to have the same compile process.
Windows boost build commands:
bootstrap.bat mingw
b2 toolset=gcc
Ubuntu boost build commands:
bootstrap.sh
b2
Can Eclipse get the OS in use on a per install basis that I can access via a globally recognizable variable?
How can I then, assuming yes, use that information to conditionally include only the right libraries?
The solution I came up with was to use two configurations: Debug-Win32 and Debug-Unix in the project properties. This keeps track of independent library & path configurations as well as different tool chains while still pulling from the same code base.

Setting Qt Creator to use the latest version of g++ and gdb on Windows

I wish to use the C++11 features in a Qt programs compiled by GNU C++ compiler (MinGW) on Windows. By this reason I can not use a version of compiler provided in Qt SDK.
I decided to use the latest versions of Qt, Qt Creator and MinGW. By this reason, I download and install these software separately. It is easy to set up the Qt Creator to use the version of Qt installed in C:\Qt folder and GNU C++ compiler from MinGW installed to C:\MinGW folder, but a debugging does not work then. More specific, I receive error:
"During startup program exited with code 0x0"
How to fix it? What is a correct setting for the debugger in the toolchain options?
QtCreator requires a patched version of gdb to works. It's a workaround
To make the --tty option work under MinGW and
To prevent gdb from freezing when attaching to a suspended process.
You have 2 alternatives (assuming that you are entirely satisfied with the prior installation of the framework and the compiler):
Download the patched gdb binary from Qt's repository or
Download the patches from Qt's site, apply them and build gdb
Install the debugger to the appropriate directory and finally resume the configuration of the debugger.