DLL Dependencies with Mingw on Windows - c++

I'm working on a program which uses autotools for its build system and compiles fine on linux. To build for windows I'm trying to get a mingw cross-compiler working for windows. Now when I compile on linux and move to windows of course I am missing some dll's that are not installed by default on windows. This leads to missing dll errors. I cannot statically link my program due to restrictions in the LGPL.
So my question is what is the correct way to cross compile in this situation? I feel like I need to wrap my exe in a installer which automatically resolves and installs the dll dependencies for windows but I haven't been able to locate something explaining how to do this. Basically I'm thinking of yum/apt-get for windows. How do I manage dll dependencies on windows? I'm a linux guy, not a windows guy, so please bear with me.

Probably the easiest thing would be if you could move your development to a Windows machine. But short of that, you could install Windows-Mingw on your Linux machine using Wine. (IIRC winetricks has even a target for this) That way you get a "feel" for the issues on windows. An alternative could be Windows in a virtual machine, but Wine should be ok for a development environment.
I also strongly suggest that you install Microsoft Visual C++. The express versions will do fine. There are a number of tools coming with MSVC++ that can make your life a lot easier, like dll-dependency checker etc. An additional excellent source of information are the Sysinternals tools from Mark Russinovich and his blog.

Related

Use GCC on Linux to cross-compile Qt apps for Windows

Ideally, I want to compile our QT-based apps, which also link other third-party libraries, on 64-bit Linux using GCC, but for a 64-bit Windows target. Again ideally, I want the result to run on 64-bit Windows without any additional runtime support, just as if we had compiled the same source code in Visual Studio. Is this possible with MinGW-w64?
I have successfully used MinGW-w64 to compile simple apps with GCC on Windows. I'm not sure how much of the MinGW-w64 installation is runtime support for executables as opposed to support for the GCC compilation environment. I did attempt to run a WinGW-w64 hello world executable on an installation of Windows without MinGW-w64, but had missing dll errors. This tells me that some runtime support was necessary, but I would like to know more precisely what is required.
If you don't want to install Windows, I think the best way is using a Virtual Machine. That's because even if the source code compiles for Windows, how could it be verified to run? You will need a real target environment to finally test your application.
From a complexity point of view, I think setting up a Windows machine (VM or not) and the necessary environment for Qt is a whole lot simpler than cross compiling bug hunting afterwards.
You can install Qt on the installed Windows, copy your project there, compile it and see the results in the real environment. This way you can cope with the minor differences when porting from one OS to another easily.
Nothing stops you from developing on Linux. You can do the entire development on Linux and just test the code on the prepared Windows by compiling and running. Sending the code to the Windows environment is simple by using git. The development process can be like :
Make a repository of your application, clone the repository both on Linux and Windows
Do the Major development on Linux and push
Pull on Windows from time to time, compile, test and make minor fixes and then push

How do you compile WebkitGTK on windows for MinGW

My experience with C++, GCC, MinGW and Cygwin is very limited. However, I already tested it and realized that Cygwin is not the ideal solution for what I am trying to do. Even though a GTK+ program with GTKWebkit works fine on Cygwin, it's not that great in terms of packaging the final project to a single .exe. The dependency on the cywin1.dll, etc... is a deal breaker.
I tested MinGW and it works flawlessly for a standard GTK only application in Windows. And the file size is great!
I tested a standard GCC compiler to compile a GTK & WebKitGtk application on Mac and it worked flawlessly.
But in the windows world where I am getting confused with GTK and WebkitGTK. What I want to do is compile a sample WebkitGTK application on Windows using MinGW. So, all the required libraries are statically linked and has a single .exe.
What are my choices? How do I actually build WebsiteGTK on Windows? Please give me the tools and as much details as you can.
FYI, QtWebkit is not going to cut it. Their licensing terms are not that commercial friendly.
I never did get WebKitGtk to compile on Windows. I think I could have got it to work using cygwin, but that's a non-starter for the project I'm working on.
I ended up using Chromium Embedded Framework instead: https://code.google.com/p/chromiumembedded/. It has clear instructions and sample apps for Mac, Linux, Windows, and mobile.
Here someone says that the easiest way to do that it's to cross-compile from virtual machine. Actually, there is binary there.
He uses OpenSUSE booted through VirtualBox. Then, using osc tool, get the mingw32-webkitgtk from windows:mingw:win32 and build it with osc.

Missing libraries when cross-compiling using mingw

I sometimes run into this problem:
1 - I develop a working C++/C program on Ubuntu Linux for Ubuntu, which uses some libraries (which are platform-independent, such as OpenSSL, Boost, GNU Scientific Library, DCMTK, and others: these are generally available from apt-get, and are installed properly).
2 - I would like to also cross-compile the program from Ubuntu to run on Windows, using mingw (x86_64-w64-mingw32-g++).
3 - The libraries are missing from mingw.
Is there a generic way to easily "convert" any library from linux-version (or source-code) into mingw installation so that it can be used to build windows a program? Each library seems to have it's own separate complicated installation instructions for mingw.
You certainly can't convert Linux libraries directly to Windows, since they almost certainly make use of Linux system calls and calling libraries (such as the C runtime library) that are specific to Linux (even if the code doesn't directly call anything else, the compiler may add function calls implicitly, such as memory allocation calls from template functions and such)
You may be able to find "replacement" Windows libraries that you can install, but yes, many probably come with a Windows installer, which makes it hard to install without using either Wine or having a "real" Windows (but then you need that to test your app, so I'm not sure how much hindrance it really is).
Some libraries may be possible to BUILD with the mingw compiler as a cross-compiler under Linux, if they are written in a portable way, which may be an easier choice than installing a ready-made Windows library. But it assumes you can find the sources...
Researching something similar right now and running into issues with libraries like openssl, boost, sqlite, libpcap,...
The best solution have found so far is to utilize WSL2 and Docker.
https://code.visualstudio.com/blogs/2020/03/02/docker-in-wsl2
WSL2 is a Linux environment for Windows (utilizes Hyper-V).
Docker allows you to make containers for both windows and Linux that can talk with each other.
I have the base code I need run under WSL2 in Linux and when I need to access it from windows I utilize docker.
This isn't a perfect solution but I hope it helps.
Some Linux programs can be compiled on Windows via Mingw.
Here is how to set the cross-compiler environment:
How to compile a Linux program with Mingw?

How to compile C++ application for Unix/Linux in Windows

I have an application written in C++ using wxWidgets. How can I compile it for Linux and Unix os like Debian, FreeBSD, CentOS, in Windows?
Thanks!
Not entirely sure if I understood the question, but I think you are asking if you can compile an application for linux using a compiler in the windows environment.
My short answer: No, but.
The but: You may be able to use Cygwin in windows, however I think there is an easier way. If you are uncomfortable with setting up your computer to have multiple partitions and installing linux on at least one of these partitions, you can use VirtualBox, VMWare, or similar virtualization software to "install" linux on your windows machine. From there you can set up build environments and such. As for how, I would leave your windows build as is, but then in create a Makefile for Linux (or use CMake to replace both your windows-specific builder (the vsproj if using visual studio, etc) and linux-specific builder (make)) so that your source will compile both on windows and linux without having to modify the actual code or project.
i would recommend to use CMake as build system

Costs and benefits of Linux-like Windows development environment

I'm taking an Introduction to C++ this semester, so I need to set up development environments in both my Windows and Ubuntu partitions (I switch between them). I was planning to use GCC in both environments for consistency and because I plan to do my serious C++ developing in Linux with GCC.
It appears that installing MSYS and MinGW is the best way to use GCC and replicate my Linux dev environment. However, just setting up MSYS and MinGW in Windows appears to be a long and arduous process, and I'm imagining that I will have limitations or compatibility problems in the future.
Do the benefits of setting up a MSYS Linux-like development environment on Windows outweigh the costs?
Will I be able to use all the libraries that I could if I were using Visual C++?
I think you're going about this the wrong way - I would actually suggest you use Visual Studio on the Windows environment, rather than going out of your way to setup GCC. It's a benefit, not a drawback, to run your code on multiple compilers from multiple vendors.
Both GCC and Visual Studio are highly conformant (at least recent versions). You won't have any trouble with standard libraries and going between them, and if you do have trouble, it's probably an issue in your code.
I've always installed cygwin on Windows. To me, Windows is completely unusable without it. I've never really run into problems with DLLs mentioned above. However, I've also rarely used the GCC compiler, so I don't know how it compares to Visual Studio for general programming. For anything with a Windows GUI or Dot Net based, I would definitely stick with Visual Studio.
If you stick with the automated installer, MinGW installation is not painful at all. Unfortunately, that currently gives you GCC 3.4.5, rather than the newer 4.4.0 release that they also provide sans installer.
In reality, for course work, 3.4.5 will be just fine, I imagine.
Use gcc on Ubuntu and Visual Studio on Windows to get exposure to both. This is an intro course so Windows, Linux, Visual Studio, gcc are just the tools you need to master C++ and data structures. Mastering the tools will come over time and they will change.
I personally develop for windows using a pure Linux environment using mingw-gcc on Linux to cross-compile for windows.
I put a tutorial on how to set it up for OpenSSL/Qt4 # http://www.limitlessfx.com
Do you do this to get .exes or just to be able to work on both OSes?
If you feel more comfortable with GCC than VC, setting up Mingw/Cygwin is possible but doesn't give you any new functionality (beside .exes). Instead, I suggest you turn one of your partitions into a virtual machine - this way you can have both OSes open at once! (My personal choice is Windows inside Linux, YMMV.)
The benefit of developing on Linux is ready availability of tons of development tools and libraries. Also, big builds are noticably faster.
Since you said "I plan to do my serious C++ developing in Linux with GCC", VC++ may not be what you really want. Many libraries just don't compile well in VC++. Try some yourself. Instead, consider running Linux on Windows. There are several ways to do this:
Use PuTTY to connect to a Linux machine, and use Xming to see the UI windows. I would only do this over a LAN.
Consider coLinux. You can run Linux under Windows and just shut-off Linux when you are done.
Consider other virtualization options like VMWare to run Linux. Pretty much the same as coLinux, but it might be easier to setup.
You may even want to install Linux directly on your machine. You can always use tools like Wine or VMWare to run Windows if you need it.