CMake: how to identify all .DLL / .SO files that are needed for an executable file?

Suppose my program requires several DLLs to work. I have to provide these DLLs for the user in my distribution. At the moment I need QtCore4.DLL, QtGui4.DLL, msvcp90.DLL, msvcr90.DLL, mylib.DLL, Kernel32.DLL ...

It would be nice if CMake could get a complete list of DLL (or .SO) files. Then I removed items such as "Kernel32.DLL" from this list and copied the DLLs into my distribution.

I canโ€™t guarantee that the next build will be done in the same version of Visual Studio, so hardcoding paths like "C: \ Program Files \ Microsoft Visual Studio 9.0 \ VC \ redist \ x86 \ Microsoft.VC90.CRT" or " E: \ Qt \ 4.6.3 "is not suitable for finding a DLL.

Thanks!

+6
source share
2 answers

You can use Dependency Walker in windows (or dumpbin tool for cmd line from visual studio). However, this is not really a CMake solution, and there is no standard solution on Cmake.

However, there is an InstallRequiredSystemLibraries module that you can use to get system DLLs (msvc [r | p] 90.dll with msvc and mingw10.dll with mingw).

+1
source

As suggested by Andrew, there are InstallRequiredSystemLibraries for finding / installing the correct C / C ++ runtime. There is also BundleUtilities , which you can use to find other dependencies of your application, library, and / or plugins.

He will never be able to select things, such as loaded plugins at runtime, but you can add them along with the library catalogs that should be used. In recent versions of CMake, several enhancements have been made to make BundleUtilities more reliable on all platforms.

+1
source

Source: https://habr.com/ru/post/887874/


All Articles