17

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.)

moskito-x
  • 11,832
  • 5
  • 47
  • 60
Magnus
  • 4,644
  • 1
  • 33
  • 49
  • Any reason why DependencyWalker is not enough for you? It does list all the dlls required by the exe as well as the ones that are not yet found in the path. – Pankaj Jul 29 '12 at 17:04
  • It's not enough because DependencyWalker isn't a Linux executable. I just found out that DW can be run in the console, but I still have to investigate if the output is such that it can be hooked into the build process. In any case I consider running DW under Wine as part of the build process to be an absolutely last resort. – Magnus Jul 29 '12 at 17:56

4 Answers4

23

As of Late 2015 there are no toolchain utilities that support listing dynamic dependencies for windows binaries (such as ldd or otool).

From my tests, a complete dependency list can usually be seen with something like:

strings MY.EXE | grep -i '\.dll$'

Hackish, but it has always worked for me.

For a complete example, try this script I use in my cross environment on linux.

h0tw1r3
  • 6,618
  • 1
  • 28
  • 34
  • 7
    I've just [created a small program (`peldd`)](https://github.com/gsauthof/pe-util) that properly reads the data structures of a portable executable (PE) to get the names of the dynamic dependencies. It uses the pe-parse library. The `strings` method is a good first order approximation, but not surprisingly it is easy to get false-positives. – maxschlepzig Feb 27 '16 at 22:04
  • 1
    @h0tw1r3, your pipeline is nearly correct. To correctly escape the '.' on the command line, you need to escape the '\', otherwise grep will see '.dll$' as the re. – Jeff Holt Apr 10 '17 at 16:56
8
$ 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.

tansy
  • 486
  • 3
  • 8
7

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
gavenkoa
  • 45,285
  • 19
  • 251
  • 303
0
    #!/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
CRB
  • 111
  • 1
  • 6