Is there a Windows/MSVC equivalent to the -rpath linker flag?

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.

Leave a Comment