Thursday, 31 July 2014

Tripping up using MinGW

One of the projects I am currently working on for HP's Advanced Technology Group is written in C/C++ and is using MinGW to cross-compile from Linux to Windows.  I have done this in several other projects quite successfully but this week I was tripped up by something when using MinGW in Fedora 20.

The build system I am using is DDM4 which is a collection of m4 files that can be used as a template for any project.  Back when working on libdrizzle 5.x we added support for MinGW cross-compiling to this.  It is designed to enable as many good compiler warnings as possible (and makes them trigger as errors) and if the compiler support PIE (Position Independent Executable) this will be enabled too.

MinGW's compiler is based on GCC and as such supports PIE to some extent.  Unfortunately I found that the '-pie' compiler option was causing the entry point to the executable to point away from the main() function.  It was hitting MinGW's dummy main() instead and the executable was returning immediately.

I have made a patch to disable PIE for MinGW and upstreamed it to DDM4.  I leave this as a warning for anyone that it hits in the future (including me).

As an extra side note, MinGW 64bit in Ubuntu seems to be completely broken.  The binary packages only contain a few text files and directories, no actual binaries.

2 comments:

  1. Have you considered using OpenWatcom for cross-compiling to Windows?

    ReplyDelete
    Replies
    1. I haven't, but given that the last stable version is 4 years old it is unlikely that some of the things I'm working on will work in it.

      Also, now I have MinGW working beautifully I don't want to spend much effort changing unless there is something significant to be gained from doing so.

      Delete

Note: only a member of this blog may post a comment.