QT enable cross-compiling using MinGW (precompiled) - c++

Good day all
I have been searching for a method of cross-compiling for QT-Creator in Linux for sometime now, and I have been having alot of trouble with it.
Background info
please note: I am on a Linux machine, and would like to cross compile Windows Apps
My system:
Ubuntu Gnome 16.10
QT Creator 4.0.2 (based on QT 5.7)
I have came across a few SO links, a few blogs with broken instructions, etc and one seeming helpful but dependencies could not be found.
I have also attempted another compiler MXE and cloned and attempted to build the MXE compiler from the GIT repo, which failed (no solution for the build error - VTK build error)
I decided to download precompiled MinGW compilers (i686 and x86_x64 versions) from sourceforge
Issue:
In QT Creator, adding the compiler is done without an issue, adding the "Kit" and selecting the newly added compiler, an red exclamation gives an error
The Compiler (x86_windows_msys_pe_64bit) cannot produce code for QT version 5.7.0 GCC 64Bit (x86_linux_generic_elf_64bit)
This occurs for both 32 + 64 bit compilers.

I think that you should have a QT version that matches your compiler ABI. The error tells you that the MinGW compiler doesn't match the Linux version of QT you have used. Therefore, get a windows version of QT and use it instead (just as you've added WinGW).
You can download Qt Binaries from here.

Related

Linux --> Windows CrossCompilation Error with QT Creator

I want to do a cross compilation on Linux for a Windows use.
I have download the compiler MinGW for C++ on my VM, I tried to set it up as a Kit, and here's the error I have :
Error: The compiler "MinGW (C++, ×86 64bit at /usr/bin/×86_64-w64-mingw32-g++)" (x86-windows-msys-pe-64bit) cannot produce code for the Qt version "Qt 6.4.1 GCC 64bit" (x86-linux-generic-elf-64bit).
Do I have to download an other version of MinGW? Which one then?
Thanks a lot !
I had the same issue on Arch. I think this "warning" is a bug. I just ignore that fact, and try build app. I wasn't get any errors, even was try to open output .exe in Windows and don't notice any issue.

How to make Qt Creator use Rosetta and x86 compiler on Mac M1?

I am using Qt 5.15.2 on my Mac mini with M1 chip. This works fine (due to Rosetta). Below is the list of compilers Qt Creator found on this computer, and among them is the C++, x86 64bit that I use. No problem.
I would like to use the same settings on a (somewhat newer) Mac Book Pro (also with M1 chip). Below is the list of compilers Qt Creator finds on this computer, the x86 is now missing!
I do not know if I have a x86 compiler on the new M1-computer. I have installed Xcode and the command line tools for XCode 13.2.
Can I somewhere tell Qt Creator that the deployment target is x86?
Does /usr/bin/clang++ only compile for the ARM/M1-chip, or can it also produce and link to x86 code?
if not, how can I find out if there is an x86 compiler on my new M1-computer?
If the compiler is missing, how to install it?
Any help would be most appreciated!
A few tips that can help, I just setup a project using Qt 5.15.2 on a 2021 M1 Mac.
Note this will likely be different for Qt >= 6.
Can I somewhere tell Qt Creator that the deployment target is x86?
Yes, you can do this using specific argument in the build settings of your kit.
Add the QMAKE_APPLE_DEVICE_ARCHS="x86_64" additional argument to qmake.
Also, add an additional CMake option: -DCMAKE_OSX_ARCHITECTURES:STRING="x86_64"
ℹ️ Click Manage Kits.. in the projects view to open the preferences editor where you can update your CMake configuration.
Does /usr/bin/clang++ only compile for the ARM/M1-chip, or can it also produce and link to x86 code?
With rosetta installed (/usr/sbin/softwareupdate –install-rosetta –agree-to-license), and the configuration above, yes you can compile and link x86 binaries.

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 install 64-bit Qt on Windows with C++11 support?

IN A NUTSHELL:
My 64-bit Qt build doesn't have C++11 support.
My Qt build with C++11 is 32-bit.
Qt5 using the online installer is 32-bit
Despite having dedicated the last 3 days of my life to this, I can't get 64-bit Qt5 to build from source.
Help! Something must be incompatible in my environment, but what could it be?
So, I need to develop 64-bit Qt apps with C++11 on Windows. I've found threads/guides here, here, here, here and here, and none of them work or apply, though I note the second of these let me build Qt 4.8.3 with C++11 support (but 32-bit). The third one looks more complicated than it should be and also involves building with VS 2010, which seems like part of the problem, so I haven't tried it. I have also wasted a lot of time trying to build previous versions with different compilers, like mingw and clang, so I'm pretty sure that cl is what I need to use.
Basically, I've gotten to the point where I can build Qt4.8.3 and execute 64-bit apps from within QtCreator 2.6.1, but I can't get full C++11 support. It finds only cl from VS 10.0 which has only very limited C++11 support. Figuring out how to get it to use cl from VS 11.0 would be one solution to my problem. But when I try
QMAKE_CXX = C:/Program Files (x86)/Microsoft Visual Studio
11.0/VC/bin/cl
the build fails with a jom Error 2, and if I select the option for building with nmake I get a similar error.
Qt 5 should have full C++11 support. But when I try to build it myself from source, it fails. The reason for this seems to be that despite running configure/make from the VS2012 x64 Cross Tools command prompt, specifying -platform win32-2012 in the configure step, and specifying QMAKE_COMPILER_DEFINES += _MSC_VER=1700 WIN32 as per
this guide, in both the win32-msvc2010 and win32-msvc2012 mkspecs, it still builds with the cl from VS 2010 and that is causing some kind of conflict. Here is my configure command:
configure -static -debug-and-release -confirm-license -opensource
-nomake tests -nomake exampmles -opengl desktop -no-libjpeg -platform win32-msvc2012
And here's the linker failure when I try to build:
At the end of the top 2 paragraphs you can see that msvc-2010 is being included, and earlier in the console output (not shown) there is -D_MSC_VER=1600 in the moc commands.
So I'm at a loss, can anyone help?
Edit: I had stated that I was building 64-bit apps with Qt5, actually I'm able to build 64-bit apps (w/o C++11 support) off a build of Qt 4.8.3. If I try this with Qt5, I get this error:
LNK1112: module machine type 'X86' conflicts with target machine type
'x64'
So this leads back to compiling Qt5 in 64-bit mode, which I can't seem to do.
Finally got a 'good enough' solution by going back and rebuilding 4.8.3 in 64-bit mode, this time ensuring that it was built with C++11 support. Since a solution involving Qt5 is what would be ideal, I'll leave this open for awhile to see if anyone can figure out how to do that.
Importantly, I note that I successfully built 64-bit, C++11-supporting 4.8.3 from the same prompt I had been using to try to build 5.0. Just changed directories. So same environment, everything. And I also have downloaded all the extra prereqs required for Qt5.
You can find prebuilds of Qt 5.0.1 SDK with 64bit support here:
http://releases.qt-project.org/digia/5.0.1/latest/
Tested and working :)
I found Qt 4.8.5 windows version qt-win-opensource-4.8.5-vs2008.exe at https://download.qt.io/archive/qt/4.8/4.8.5/ for VC++ projects.

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.