Home > Blockchain >  Find required dll's after linking to an external .lib file
Find required dll's after linking to an external .lib file

Time:12-08

In one of my current projects, i am required to build a windows executable. We use external libraries (libpq). CMake finds the .lib files and is able to build against the library. However, we require to bundle the dependencies of libpq. We don't know them, as they can differ from the used libpq version.

Is there any way to scan for these dependencies (and their dependencies), so we can bundle them with the help of CPack?

CodePudding user response:

You can use dumpbin.exe, a command line tool which comes bundled with Visual Studio or the Windows SDK, ​with the /imports command line. You can run it against on both your main EXE to discover which DLLs its dependent on as well on individual DLLs to see what they depend on.

Often times, I'll just run dumpbin /imports foo.exe | findstr /i dll to quickly find out what DLLs it depends on.

Another useful tool is depends (Dependency Walker). It's a bit dated, but it's a GUI version of dumpbin that shows you where the system finds dependent DLLs.

There's also listdll from the Sysinternals group at MS.

We don't know them, as they can differ from the used libpq version.

Yes you do. Whatever version of libpq you build with, you should ship the corresponding DLLs (if any) from that same version.

You typically hardcode your binary file dependencies instead of trying to do some build environment trickery. That is, you know you are linking with a DLL import library, you should know which DLLs you need to ship alongside your EXE.

If libpq is a completely standalone LIB that just statically links into your EXE, you are likely done. No further work to consider.

If libpq is a stub lib with a corresponding DLL, you ship the DLL (e.g. "libpq.dll") and its dependencies in the same folder as your EXE.

Again, dumpbin.exe will help you find the dependencies. Also, read this: https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order

  • Related