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

后端 未结 3 419
渐次进展
渐次进展 2020-12-04 17:30

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 acco

相关标签:
3条回答
  • 2020-12-04 18:08

    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.

    0 讨论(0)
  • 2020-12-04 18:19

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

    0 讨论(0)
  • 2020-12-04 18:22

    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.

    0 讨论(0)
提交回复
热议问题