CMake:如何确定可执行文件所需的所有 .DLL/.SO 文件?

2021-12-25 00:00:00 dll cmake c++

假设我的程序需要几个 DLL 才能工作.我应该在我的发行版中向用户提供这些 DLL.现在我需要 QtCore4.DLL、QtGui4.DLL、msvcp90.DLL、msvcr90.DLL、mylib.DLL、Kernel32.DLL...

Let's assume my program needs several DLL's to work. I should provide that DLLs to the user in my distribution. For now I need QtCore4.DLL, QtGui4.DLL, msvcp90.DLL, msvcr90.DLL, mylib.DLL, Kernel32.DLL...

如果 CMake 能够获得 DLL(或 .SO)文件的完整列表,那就太好了.然后我会从该列表中删除诸如Kernel32.DLL"之类的项目,并将这些 DLL 复制到我的发行版中.

Would be nice if CMake could get full list of DLLs (or .SO) files. Then I would remove items like "Kernel32.DLL" from that list and copy the DLLs to my distribution.

我不能保证下一个构建将在相同版本的 Visual Studio 上完成,因此硬编码路径如C:Program FilesMicrosoft Visual Studio 9.0VCedistx86Microsoft.VC90.CRT" 或 "E:Qt4.6.3" 不适合搜索 DLL.

I can't guarantee the next build will be done on the same version of the Visual Studio, so hard-coding paths like "C:Program FilesMicrosoft Visual Studio 9.0VCedistx86Microsoft.VC90.CRT" or "E:Qt4.6.3" is not good for searching for the DLLs.

谢谢!

推荐答案

您可以在 windows 上使用 Dependency Walker(或来自 Visual Studio 的 cmd-line dumpbin 工具).然而,这并不是真正的 CMake 解决方案,而且 Cmake 也没有真正的标准解决方案.

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

但是,InstallRequiredSystemLibraries 模块,您可以使用它来获取系统 dll(msvc[r|p]90.dll 与 msvc 和 mingw10.dll 与 mingw).

There is, however, the InstallRequiredSystemLibraries module, which you can use to get the system dlls (msvc[r|p]90.dll with msvc and mingw10.dll with mingw).

相关文章