Our C++ project uses mixed dynamic (Qt) and static (ffmpeg, portaudio) libraries. At the moment I’m trying to port it to windows and the debug executable produced by mingw (via QtCreator) refuses to start (the error is such-and-such is not a valid executable). The release executable with the same linkage starts (but has some problems I would like to debug).
To narrow down the possible cause of the problem I made a dummy project that does nothing, just links to the same set of libraries and it has exactly the same problem. As long as I disable linking to both static libraries debug executable works, as soon as I enable any one of them the debug executable is broken.
I haven’t tried building dll versions of ffmpeg and portaudio yet, but I would like to understand what’s going wrong with the case as it is.
This is because of a nasty bug in the ld linker in the MinGW package that’s included in some Qt downloads.
The ld linker that’s included with the MinGW 4.4.0 package has a bug in the default linker script for placement of the
.debug_pubtypessection, which is where symbols or some debug information gets stored. The linker script causes that section to get placed at a virtual address that the loader doesn’t like (or something like that). Sometimes – if you don’t have symbols in the image, or if the symbols are small enough (or maybe there’s some other factor) the problem doesn’t show up.You have a couple of options:
-T <scriptfile>option to specify a correct linker script to ldHere’s the default linker script from ld 2.21, which should work if you pass it in to the version you have (unfortunately my notes don’t say what the version number of the ld with the problem is – if you could drop a comment about that so I can update my notes, I’d appreciate it).
I don’t mind telling you that I had to go through about a week of pain to figure this out. Windows doesn’t give any real help at all about the reason it thinks the executable is invalid, and debugging – even with cdb or WinDBG from the “Debugging Tools for Windows” – is little help. Windows seems to make the determination that the PE is invalid from deep within the bowels of the loader in the NT kernel, and doesn’t give any information that I could find about the reason (it would have been nice to have something put into the event log or something).
I ultimately figured out this problem using Wine’s (!!) tracing facility. I wonder if the ‘checked’ version of Windows would give more information about the problem, but I was having a hell of a time getting that downloaded and installed.