4
votes

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.

3

3 Answers

1
votes

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...

1
votes

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.

-2
votes

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?