MinGW32, Cross Compile Packages

Well, so I've been looking around for packages to build a cross compile environment. It was just a complete mess finding the correct DLLs, or having to compile one package only to find out it needed thirty other packages that also needed compiling, because precompiled packages wouldn't be compatible.

There are plenty of excellent guides on how to set up a cross compile environment. I'm not going to explain this here. My host is Ubuntu 64, and my target Win32.

Nobody ever wrote in any guide, that Fedora has all the mingw32 packages neatly compiled and ordered all over the web. There are massive numbers of FTP-servers mirroring hundreds of mingw32 packages, so no need to compile anything, and all DLLs are compatible! What a waste of time, spent on finding this out!

All that is needed is to open FileZilla (or whichever your FTP-client is), locate the local FTP-server (which since I live in Stockholm is ftp.sunet.se), find the right directory and download galore. The right directory is usually something similar to "/pub/.../fedora/.../i386/.../". Google "fedora mingw32 glib rpm" and you'll get a number of pages listing ftp-servers. Look at the URL where the file is located, and in the same directory you'll find the rest of the mingw32 packages. You won't need any password to open the server with your FTP-client.

The packages are RPM-files, incompatible with Ubuntu, but easily extracted with for example File Roller. They usually extract to a directory similar to "/usr/i686-w64-mingw32.../mingw/" (with a few "/usr/bin" and "/usr/share" that you can safely ignore, only the files in the ".../mingw/" directory is of interest) and so the files are simply moved to the mingw32 directory, which happens to be /usr/i686-w64-mingw32 on my computer.

Most pkgconfig files need to be corrected, so that the compiler will find the right libraries and headers. There's a simple command to correct all .pc files at once:

$ find /usr/i686-w64-mingw32/lib/pkgconfig -type f -exec sed \
> -i "s/^prefix=.*$/prefix=\/usr\/i686-w64-mingw32/g" {} \;

This command lists all files in the pkgconfig directory, and executes a regex replace. This will do the trick, at least most of it. If it doesn't, adjust the regex segment, or simply edit the files manually.

After this, cross compiling runs smoothly.

No comments:

Post a Comment