Finding DLLs required of a Win exe on Linux (cross-compiled with mingw)?

Viewed 7487

I'm using MinGW on Linux to cross-compile to Windows. Getting that working was a breeze. Packing it up with the required DLLs was not quite as simple though. The solution at the moment is to run the executable on Windows and copy over DLLs until it actually runs.

Is there a tool for Linux that lists the DLLs required by my Windows .exe? (Something like a combination of ldd and DependencyWalker.)

4 Answers

Check that your utility supports PE format with objdump --help. Install cross compiler toolsets for MinGW if not (like https://packages.debian.org/sid/mingw-w64).

Than look to:

objdump --private-headers $EXE
$ objdump -p program.exe | grep "DLL Name:"
        DLL Name: KERNEL32.dll
        DLL Name: msvcrt.dll

FWIW one can use objdump with -p (or -x) option. It's so much better than sifting through '.dll' strings as it most likely will give lot of false positives.

    #!/bin/sh

    notfounddlls='KERNEL32.dll'
    dllbase=/usr/x86_64-w64-mingw32

    nc=1
    while [ $nc -gt 0 ];
    do
       nc=0
       for f in *.exe *.dll
       do
          for dep in $(strings $f | grep -i '\.dll$')
          do
             if [ ! -e $dep ]; then
                echo $notfounddlls | grep -iw $dep > /dev/null
                if [ $? -ne 0 ]; then
                   dllloc=$(find $dllbase -iname $dep)
                   if [ ! -z $dllloc ]; then
                      cp $dllloc .
                      echo "Copying "$(basename $dllloc)
              nc=$(($nc + 1))
           else
              notfounddlls="$notfounddlls $dep"
           fi
        fi
             fi
          done
       done
    done
    echo "System DLLS: "$notfounddlls
Related