-1

I'm trying to run a piece of software I built in MSYS2 MINGW32 shell. The software is 32bits (don't have time to port it to 64bits) and there is one statically linked executable. Here is how I setup the build environment:

  1. Installed a fresh copy of MSYS2;
  2. $ pacman -Syu
  3. Installed the following packages: git mingw-w64-i686-gcc mingw-w64-i686-cmake mingw-w64-i686-SDL mingw-w64-i686-SDL_mixer mingw-w64-i686-zlib mingw-w64-i686-libpng mingw-w64-i686-make
  4. Git checkout the repo
  5. Run the build in CMake
  6. Build runs fine and the exe is generated.

Now the problem starts: the executable can't run and displays an error message about missing DLLs. I copied the missing DLLs to the same folder of the executable, and them another error message pops up complaining about error 0xC000007B, which I tracked down to be missing dependencies. After a while I figured out that the problem was that some of the DLLs is missing a dependency itself. Copied this last dependency to the folder.

Now, the big question: I can run the exe perfectly fine in the MINGW32 shell but I can't run it neither in cmd.exe nor by double-clicking in Windows Explorer and this is a problem (I can't ship a software this way). Is there any way to produce a binary that is able to run from explorer and from cmd.exe? What is the cause of this problem? Can it be mitigated?

  • 1
    You forgot to copy some DLLs, that's always the reason. Install `mingw-w64-i686-ntldd` and run `ntldd -R my_app.exe` to get a list of all used dlls, then copy the ones that are in `/mingw32/bin`, and skipping the ones in `C:\Windows`. – HolyBlackCat Nov 10 '21 at 19:04
  • Did that! The problem is that it seems none of the missing ones are from /mingw32/bin. Here is the list: https://gist.github.com/danielt3/459593eddd4d0ceeeecb210bef23ec9e – daniel.franzini Nov 10 '21 at 19:18
  • Can you show the full output? – HolyBlackCat Nov 10 '21 at 19:24
  • Yes. https://gist.github.com/danielt3/459593eddd4d0ceeeecb210bef23ec9e – daniel.franzini Nov 10 '21 at 19:32
  • Hmm. Check if any dlls in this list are present in `/mingw32/bin`, and weren't already copied. (Ignore the location ntldd shows you. It's possible that a dll exists in both `C:\Windows` and in `/mingw32/bin`). – HolyBlackCat Nov 10 '21 at 19:39
  • To make sure, I put a printf right in the beginning of main. In the MINGW32 shell, it works. In the cmd or explorer, the program exits without doing anything. – daniel.franzini Nov 10 '21 at 19:53
  • Again, can you confirm that none of the dlls that ntldd says are loaded from `C:\Windows` (or subdirectories) are also present in `/mingw32/bin`? – HolyBlackCat Nov 10 '21 at 20:04
  • 1
    Also try running `ntldd -R` from both MINGW32 shell and from CMD and compare the output. – HolyBlackCat Nov 10 '21 at 20:05
  • Just did! The list is exactly the same (except the loading addresses for libraries, of course). – daniel.franzini Nov 10 '21 at 20:35
  • This is weird. Next step, `echo $PATH` in MINGW32 shell. Then set the same path in CMD (convert paths to windows-style of course, and replace separators from `:` to `;`), and try running your app. If it does run, figure out which specific entry in the PATH is the culprit. – HolyBlackCat Nov 10 '21 at 20:38

1 Answers1

0

I solved my problem!

After a lot of research, I realized that nothing was wrong with my MSYS2 build/setup/dependencies. The real problem was that CMake hide one parameter for the linker: -mwindows. Actually, the CMake find_package routine from one of the libraries I'm using (SDL) added this parameter to the linker command line parameters.

Adding a -mconsole to the linker parameters (using add_link_options("-mconsole")) solved the problem. The CLI now works as expected.

Thank you all for your help.