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

4

18

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

Sarraute answered 28/7, 2012 at 17:3 Comment(2)
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.Tragicomedy
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.Sarraute
C
25

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.

Cryogenics answered 16/10, 2015 at 15:28 Comment(2)
I've just created a small program (peldd) 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.Lettering
@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.Dinger
H
12
$ 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.

Hemielytron answered 1/4, 2021 at 22:51 Comment(0)
N
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
Novelize answered 2/11, 2019 at 13:27 Comment(0)
L
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
Lucier answered 24/8, 2019 at 23:7 Comment(1)
Provide explanation, what and why you are doing.Geilich

© 2022 - 2024 — McMap. All rights reserved.