Is there a Windows/MSVC equivalent to the -rpath l

2019-01-31 15:51发布

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!

3条回答
Explosion°爆炸
2楼-- · 2019-01-31 16:11

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.

查看更多
Anthone
3楼-- · 2019-01-31 16:17

"Isolated applications" is a mechanism for embedding an XML manifest that describes the DLL dependencies.

查看更多
男人必须洒脱
4楼-- · 2019-01-31 16:28

The search order for DLLs in Windows is described on this page on MSDN. If you're using run-time dynamic linking, you can specify the folder when you call LoadLibrary.

查看更多
登录 后发表回答