是否有与 -rpath 链接器标志等效的 Windows/MSVC? [英] Is there a Windows/MSVC equivalent to the -rpath linker flag?

查看:23
本文介绍了是否有与 -rpath 链接器标志等效的 Windows/MSVC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Linux/GCC 上,我可以使用 -rpath 标志来更改共享库的可执行文件搜索路径,而无需调整环境变量.

On Linux/GCC I can use the -rpath flag to change an executables search path for shared libraries without tempering with environment variables.

这也可以在 Windows 上完成吗?据我所知,总是在可执行文件的目录和 PATH 中搜索 dll.

Can this also be accomplished on Windows? As far as I know, dlls are always searched in the executable's directory and in PATH.

我的场景:我想根据共享库的属性(32/64 位/调试/发布)将它们放在不同的位置,而无需考虑唯一名称.在 Linux 上,这很容易通过 rpath 完成,但我还没有在 Windows 上找到任何方法.

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.

感谢您的任何提示!

推荐答案

遗憾的是没有与 RPATH 的直接类似物.有多种替代可能性,每一种可能性都以自己的特殊方式对您来说很可能是不受欢迎的.

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.

鉴于您无论如何都需要为每个构建风格使用不同的 exe 以避免运行时库冲突,因为您可能猜想最简单的方法是将每个 exe 与每组 DLL 放在同一文件夹中.

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.

正如您所提到的,最通用的方法是通过使用批处理文件来引导 exe 来更改 PATH 变量.

As you also mentioned, the most universal method is to change the PATH variable by using a batch file to bootstrap the exe.

您可以改为在运行程序之前更改当前工作目录到所需的 DLL 文件夹.

You could instead change the current working directory before running the program to the desired DLL folder.

您可以使用功能SetDllDirectoryAddDllDirectory 在您的 exe 中.这可能是最接近 RPATH 的,但仅适用于 WinXP SP1 或更高版本.

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.

如果您愿意更改每个 exe 风格的文件名,您可以使用App Paths"注册表项.每个 exe 都需要一个唯一的文件名.

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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