简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM