Application compiled in mingw-w64/msys2, "the application was unable to start correctly (0xc00007b"
Asked Answered
W

2

8

After compiling an application in the mingw-w64 64-bit Shell, it runs fine inside the shell, but gives an error the application was unable to start correctly (0xc00007b) when run normally, outside the shell.

I moved some of the necessary DLLs from the msys2/mingw-w64 bin directories when it complained about missing them, but now it gives this opaque error. What am I doing wrong?

Weepy answered 16/12, 2015 at 23:7 Comment(0)
W
8

Error 0xc00007b basically means "invalid image format" which usually happens when mixing 64-bit and 32-bit DLLs. What is happening, is that you have a 64-bit application, looking for a particular DLL, which is in the global path, but the one in the path is 32-bit. Therefore, the problem is: it does not complain about the missing DLL, it just tries to load it. Since it is a 32-bit application, and your application is a 64-bit application, you get error 0xc00007b.

The solution is to copy all the dependent DLLs over to the application path.

The next problem is you don't know which ones.

What you can do with msys2 shell is: go to the directory and run the command:

ldd application.exe

This will give you a list of DLLs the application depends on. Copy the msys2/mingw-w64 related DLLs to the directory. This will allow the application to find them before looking in the PATH and finding the 32-bit DLLs.

Weepy answered 16/12, 2015 at 23:7 Comment(5)
Dependency Walker displays all dependencies, that are linked using compile-time dynamic linking. Similar to your suggest approach to use ldd it will not account for dependencies that are linked using runtime dynamic linking (Dependency Walker allows you to profile your application, so you might catch some of them this way).Kamala
@Kamala sure, I am aware of dependency walker. It's a great tool. Haven't used it in years. ldd is part of mingw-w64 so i found it useful to use that.Weepy
Thanks for the useful thread. Not sure yet whether it's causing my problem, but it's valuable either way. Since it might be related: (A) Can this occur when conversely running a 32-bit cross-compiled program on a 64-bit OS, and (B) Do you know why, whereas running from Explorer or Command Prompt gives this error - when running from the same MSYS2-supplied mingw32 shell, the program simply exits immediately with no apparent error?Eberly
Unfortunately at least in my case ldd reported "a few" dependencies, including some rather unuseful ones like ??? => ??? (0xd0000) whereas dependency walker showed me the ones that were actually missing :|Doited
"copy all the dependent DLLs", in my case ldd is showing dependency on both /c/Windows/System32/ntdll.dll and /c/Windows/SysWow64/ntdll.dll, tried both, none workThresathresh
C
1

use Process Monitor and see what .dll it's trying to read/Query:
https://learn.microsoft.com/en-us/sysinternals/downloads/procmon
export to .csv
then use Transformer: Filter Lines...
https://marketplace.visualstudio.com/items?itemName=dakara.transformer

if you want to have an easy time, run the .exe using mingw shell,
(it Will succeed, or else you're at the wrong question),
then you can see all the .dll it successfully loaded/read from /mingw32/bin in my case

C answered 19/4 at 10:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.