7

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?

Realz Slaw
  • 3,138
  • 1
  • 24
  • 38

1 Answers1

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.

Realz Slaw
  • 3,138
  • 1
  • 24
  • 38
  • 2
    [Dependency Walker](http://www.dependencywalker.com/) 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). – IInspectable Dec 17 '15 at 00:05
  • @IInspectable 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. – Realz Slaw Dec 17 '15 at 00:48
  • 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? – underscore_d Jun 11 '16 at 14:56
  • 3
    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 :| – rogerdpack Jun 15 '16 at 08:45
  • "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 work – 0xB00B Feb 01 '22 at 10:18