有没有办法在 Windows 中模拟 LD_LIBRARY_PATH? [英] Is there any way to simulate LD_LIBRARY_PATH in Windows?

查看:32
本文介绍了有没有办法在 Windows 中模拟 LD_LIBRARY_PATH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序可以做一些图形.当我以交互方式运行它时,我希望它使用系统中的 OpenGL 来提供硬件加速图形.当我批量运行它时,我希望能够重定向它以使用 Mesa GL 库,以便我可以使用 OSMesa 功能渲染到屏幕外缓冲区.如果选择了批处理启动选项,则通过执行 LoadLibrary/GetProcAddress 启用 OSMesa 功能.

I have a program do so some graphics. When I run it interactively, I want it to use OpenGL from the system to provide hardware accelerated graphics. When I run it in batch, I want to be able to redirect it to use the Mesa GL library so that I can use OSMesa functionality to render to an offscreen buffer. The OSMesa functionality is enabled by doing a LoadLibrary/GetProcAddress if the batch start up option is selected.

在 Linux 上,使这项工作相当容易.通过使用包装脚本来调用程序,我可以执行以下操作:

On Linux, its fairly easy to make this work. By using a wrapper script to invoke the program, I can do something like this:

if [ "$OPTION" = "batch" ]; then
  export LD_LIBRARY_PATH=$PATHTO/mesalibs:$LD_LIBRARY_PATH
fi

可以在 Windows 中执行此操作吗?

It is possible to do something this in Windows?

当我尝试向 PATH 变量添加目录时,程序继续转到系统 opengl32.dll.让程序使用 Mesa GL/OSMesa 共享库的唯一方法是让它们与我的程序位于同一目录中.但是,当我这样做时,程序将永远不会使用系统 opengl32.dll.

When I try adding a directory to the PATH variable, the program continues to go to the system opengl32.dll. The only way I can get the program to use the Mesa GL/OSMesa shared libraries is to have them reside in the same directory as my program. However, when I do that, the program will never use the system opengl32.dll.

推荐答案

如果我理解你的意思,那么你的进程启动时加载了错误版本的 opengl32.dll,即 加载时动态链接.如果不改变这一点,可能没有好的方法可以解决您的问题.

If I've understood what you're saying correctly, the wrong version of opengl32.dll is being loaded when your process starts up, i.e., load-time dynamic linking. There is probably no good way to solve your problem without changing this.

你说不能方便使用 运行时动态链接 (LoadLibrary/GetProcAddress) for opengl32.dll 因为对它的调用来自 Qt 库.但是,我认为 Qt 库本身是动态链接的,因此您应该能够通过使用运行时链接来解决您的问题.在这种情况下,如果您在加载 Qt 库之前加载 opengl32.dll,您应该能够明确选择要加载的 opengl32.dll 版本.

You say you can't use conveniently use run-time dynamic linking (LoadLibrary/GetProcAddress) for opengl32.dll because the calls to it are coming from the Qt library. I presume that the Qt library is itself dynamically linked, however, so you should be able to solve your problem by using run-time linking for it. In this scenario, provided you load opengl32.dll before you load the Qt library, you should be able to explicitly choose which version of opengl32.dll you want to load.

您可能需要考虑使用延迟加载以简化从加载时链接到运行时链接的过程.在这种情况下,第一次调用 Qt 库会导致它自动加载,您只需要先显式加载 opengl32.dll.

You might want to consider using delayed loading in order to simplify the process of moving from load-time to run-time linking. In this scenario, the first call into the Qt library causes it to be loaded automatically, and you'll just need to explicitly load opengl32.dll first.

这篇关于有没有办法在 Windows 中模拟 LD_LIBRARY_PATH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆