Magnus
Magnus

Reputation: 4714

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

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

Upvotes: 18

Views: 11480

Answers (4)

tansy
tansy

Reputation: 566

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

Upvotes: 14

gavenkoa
gavenkoa

Reputation: 48723

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

Upvotes: 8

CRB
CRB

Reputation: 121

    #!/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

Upvotes: 0

h0tw1r3
h0tw1r3

Reputation: 6818

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.

Upvotes: 25

Related Questions