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

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.

Related

whats the difference between mingw and mingw64 [duplicate]

What are the differences between MinGW, MinGW-w64 and MinGW-builds?
And which one should I use to compile c++ 11 source code with the Eclipse IDE on a Windows 8 machine?
MinGW is a GCC-port for Windows. Not all of the Windows API is supported (but for many programs the supported stuff is sufficient) and it´s only for 32bit-Programs (which often can run on 64bit-Windows too, but some can´t, and you can´t compile them as 64bit).
MinGW-w64 is a improved version which supports both 32bit and 64bit, and some more of the WinAPI (still not all, because thats much work, but more than MinGW).
MinGW-w64 only provides their source code, but no binaries to "just use" the compiler.
MinGW-builds is a somewhat separate project to provide binaries in the most useful configurations. To get a specialized build of MinGW-w64, manual compiling is still possible.
Using the MinGW-builds self-installer is the easiest way, if nothing unusual is needed. Also see here for help with the self-installer.
Mingw compiles your code to Windows binaries that run under Windows.
Windows subsystem for Linux (WSL) makes Linux binaries. You can install other Linux programs under WSL, except if you need a graphical interface. You can access the Windows filesystem from WSL, but not vice versa.
Cygwin makes Windows binaries that can run under Windows outside the Cygwin shell, as long as you have the Cygwin DLL. This gives a Linux-like environment that is fully compatible with Windows.

Publishing exe application

I have written a code in C and C++ that uses PCRE library. To test my code I use Cygwin which contains MinGW and it works fine when I run my code from console but I get the following error when I try to install the .exe file.
The program can't start because cygwin1.dll is missing from your computer
How can I publish .exe application that works on windows with all its dependancies?
As it depends on cygwin1.dll is NOT a mingw program it is a cygwin one.
If you want to built a mingw program you need
1) install a cygwin to minw cross compiler; two are available depending on your arch
mingw64-i686-gcc
mingw64-x86_64-gcc
2) install the needed additional libraries, depending on your arch and the pcre release you want to use:
mingw64-i686-pcre
mingw64-i686-pcre2
mingw64-x86_64-pcre
mingw64-x86_64-pcre2
3) set your build as cross one.

Run cygwin built exe in windows without cygwin's environment

I'm trying to port a linux software in Windows.
My software depends on gtk, boost and libgerbv (which I've manually compiled on cygwin)
I've successfully compiled it and it works if I run it in the cygwin's terminal, but if I copy the .exe in a folder with cygwin1.dll and I run it, it terminates silently
Same result if I run it within cmd.exe.
How can I "export" this executable outside the cygwin environment? I want to distribute it with just the needed shared libraries and cygwin1.dll
Thanks
"How can I "export" this executable outside the cygwin environment?"
In short: That's not possible. You'll need to have a cygwin environment installed on the target machine, and run the programs created in cygwin from a cygwin shell.
Cygwin requires a number of it's own .dll files, to bind to the underlying Windows OS. These cannot be just copied to another windows system without having a complete installation of cygwin.
Here're some more details about this: What is the difference between Cygwin and MinGW?
That's why I prefer to use MinGW to target windows systems portably. Cygwin has it's powers and right to exist, when it comes to cross compile code for different (e.g. embedded) targets running on windows as host.

What is the difference between MinGW, MinGW-w64 and MinGW-builds?

What are the differences between MinGW, MinGW-w64 and MinGW-builds?
And which one should I use to compile c++ 11 source code with the Eclipse IDE on a Windows 8 machine?
MinGW is a GCC-port for Windows. Not all of the Windows API is supported (but for many programs the supported stuff is sufficient) and it´s only for 32bit-Programs (which often can run on 64bit-Windows too, but some can´t, and you can´t compile them as 64bit).
MinGW-w64 is a improved version which supports both 32bit and 64bit, and some more of the WinAPI (still not all, because thats much work, but more than MinGW).
MinGW-w64 only provides their source code, but no binaries to "just use" the compiler.
MinGW-builds is a somewhat separate project to provide binaries in the most useful configurations. To get a specialized build of MinGW-w64, manual compiling is still possible.
Using the MinGW-builds self-installer is the easiest way, if nothing unusual is needed. Also see here for help with the self-installer.
Mingw compiles your code to Windows binaries that run under Windows.
Windows subsystem for Linux (WSL) makes Linux binaries. You can install other Linux programs under WSL, except if you need a graphical interface. You can access the Windows filesystem from WSL, but not vice versa.
Cygwin makes Windows binaries that can run under Windows outside the Cygwin shell, as long as you have the Cygwin DLL. This gives a Linux-like environment that is fully compatible with Windows.

How to compile Qt statically under Windows?

After successfully installing the Qt SDK 4.7.4 (MingW) and building an application I can find no way to deploy my program. Qt is really nice, but to deploy under Windows means to leave he surfaced road.
First the executable requires QtCore4.dll plus some other DLLs, but the Creator does not copy them into the deploy folder. Do I really have to try DEPENDS.EXE, to find out which DLLs are required, and then cull them manually from somewhere under C:/QtSDK?
Be that as it may, preferably I want to link statically. There are few recipes on the net how this can be done (e.g. here and here). So I launched a Qt 4.7.4 Desktop (MingW) command prompt. The Qt Reference Documentation tells to run CONFIGURE.EXE, but there's no CONFIGURE.EXE and no CONFIGURE.CMD, not under C:/QtSDK and not under C:/.
What am I missing?