Link qt dll 到多个可执行文件

Link qt dlls to multiple executables

我在一个特定目录的不同子目录中有四个不同的 .exe。所有程序都需要完全相同的 .dll(Qt5Core、Qt5Gui 和 Qt5Widgets)。有没有办法将这三个 .dll 放在根目录中,而不必将它们复制到每个子目录中?

是的,您正在使用 Windows,您可以将根目录作为路径添加到

环境变量

计算机->属性->高级系统设置->环境变量

Here you find the order 在 Windows 上搜索 DLL 路径:

由于默认启用安全DLL搜索模式,顺序为

  1. The directory from which the application loaded.
  2. The system directory. Use the GetSystemDirectory function to get the path of this directory.
  3. The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
  4. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
  5. The current directory.
  6. The directories that are listed in the PATH environment variable. Note that this does not include the per-application path specified by the App Paths registry key. The App Paths key is not used when computing the DLL search path.

因此,最简单的做法是确保从放置 DLL (5.) 的工作目录中 运行 您的应用程序。这可以通过编写一个启动程序 .bat 文件来完成,该文件首先导航到那里,然后 运行s 相对于 DLL 目录的应用程序。

另一种方法是将 DLL 目录添加到起始 .bat 文件 (6.) 中的 PATH。

在这两种情况下,您都需要为每个要 运行.

的 .exe 编写一个包装器脚本

如果您可以确保指向应用程序的链接正确设置了工作目录,则可以避免这种情况。如果您有一个安装程序为用户创建快捷方式,并且您知道用户不会通过右键单击 .exe 自己创建快捷方式,那么这将起作用。


可能还有一种使用 hardlinks or junctions 的方法,但我不知道您是否可以在 Linux 上复制和部署符号链接之类的东西,或者您是否需要在目标系统上创建它们.