问题描述
在Linux / GCC上,我可以使用-rpath标志来更改共享库的可执行文件搜索路径,而不用环境变量进行回火。这也可以在视窗?据我所知,dll总是在可执行文件的目录和PATH中进行搜索。
我的场景:我想根据自己的属性(32 / 64bit / Debug / Release)将共享库放入位置,而不需要使用唯一的名称。在Linux上,这很容易通过rpath完成,但我还没有在Windows上找到任何方法。
感谢任何提示!
可悲的是,没有直接的类似于RPATH。有一些替代的可能性,每个人最有可能以自己的特殊方式对您不利。
鉴于您需要为每种构建风格使用不同的exe避免运行时库冲突,因为你可能会猜到最简单的做法是将每个exe放在与每组DLL相同的文件夹中。
正如你也提到的,最通用的方法是通过使用批处理文件来引导exe来更改PATH变量。
您可以改变当前工作目录,然后再将程序运行到所需的DLL文件夹。
您可以使用函数或。这可能是最接近RPATH,但仅适用于WinXP SP1或更高版本。
如果您愿意更改每个exe风格的文件名,您可以使用App Paths注册表项。每个exe都需要一个唯一的文件名。
On Linux/GCC I can use the -rpath flag to change an executables search path for shared libraries without tempering with environment variables.
Can this also be accomplished on Windows? As far as I know, dlls are always searched in the executable's directory and in PATH.
My scenario: I would like to put shared libraries into locations according to their properties (32/64bit/Debug/Release) without taking care of unique names. On Linux, this is easily be done via rpath, but I haven't found any way doing this on Windows yet.
Thanks for any hints!
Sadly there is no direct analogue to RPATH. There are a number of alternative possibilities, each of them most likely undesirable to you in its own special way.
Given that you need a different exe for each build flavor anyway to avoid runtime library clashes, as you might guess the easiest thing to do is to put each exe in the same folder as each set of DLLs.
As you also mentioned, the most universal method is to change the PATH variable by using a batch file to bootstrap the exe.
You could instead change the current working directory before running the program to the desired DLL folder.
You can use the function SetDllDirectory or AddDllDirectory inside your exe. This is probably the closest to an RPATH, but only works on WinXP SP1 or later.
If you're willing to alter the file name of each exe flavor, you can use the "App Paths" registry key. Each exe would need a unique filename.
这篇关于是否有一个等同于-rpath链接器标志的Windows / MSVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!