SWIG允许您使用-dllimport
命令行参数指定要导入C#的DLL。
导入一个名称取决于Debug版本或Release版本的DLL怎么样?对于遵循Microsoft约定的d
后缀附加到Debug版本的DLL,会发生这种情况。 ucrtbase.dll
用于发布版本,ucrtbased.dll
用于调试。
如果允许-dllimport
指定符号常量,则该常量的值可能取决于是否定义了DEBUG
,但这似乎并非如此。
我认为您可以使用静态构造函数和the SetDllDirectory
of suggestion of this this answer做您想做的事情。
为了测试这一点,我把这个例子放在一起:
SetDllDirectory
您必须像这样用SWIG来构建它才能%module foobar
%pragma(csharp) imclasscode=%{
[global::System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool SetDllDirectory(string lpPathName);
static $imclassname() {
if (isDebug)
SetDLLDirectory("path/to/directory/with/debugDll");
else
SetDLLDirectory("path/to/directory/with/regularDll");
}
%}
:
suppress the default static constructor
相当如何区分真实代码中的swig3.0 -DSWIG_CSHARP_NO_IMCLASS_STATIC_CONSTRUCTOR -csharp test.i
,我不太清楚-也许使用isDebug
,然后使用this to find the current HMODULE
来查看它是否是您的调试版本。