简体   繁体   English

使用SWIG为C#生成AnyCPU程序集

[英]Generate AnyCPU assembly for C# with SWIG

is it possible to create a AnyCpu assembly with SWIG? 是否可以用SWIG创建AnyCpu装配? I have both the x86 and x64 binaries compiled (c++) and I'm able to generate a SWIG P/Invoke Wrapper. 我同时编译了x86和x64二进制文件(c ++),并且能够生成SWIG P / Invoke Wrapper。 But the wrapper is dependent on the invoked native dll (which is CPU specific). 但是包装程序依赖于调用的本机dll(特定于CPU)。 But I like the idea of let the executable decide instead of having two different executables. 但是我喜欢让可执行文件决定而不是拥有两个不同的可执行文件的想法。 I'm would put the dlls in seperate folders (eg named x64/x86) if this is helpful. 如果有帮助,我会将dll放在单独的文件夹中(例如,命名为x64 / x86)。 Or do I have to write a handmade wrapper in C# which decides to load the right dll? 还是我必须用C#编写一个手工包装程序来决定加载正确的dll?

Thanx for input. 感谢输入。

It seems you have to roll you own wrapper. 看来您必须自己包装纸。

I came across the solution CLRZMQ was using for similar reasons. 我遇到了出于类似原因而使用CLRZMQ的解决方案。

They solved it pretty well by embedding both .dll versions and extracting those accoring to the current platform: 他们通过嵌入两个.dll版本并提取符合当前平台的版本,很好地解决了该问题:

They determined the running platform by using Environment.Is64BitProcess and adding a x86 or x64 suffixe + version string before extracting and loading the correct dll. 他们通过使用Environment.Is64BitProcess并添加x86或x64后缀+版本字符串来确定正在运行的平台,然后再提取并加载正确的dll。

Here is their solution to the problem and here is the corresponding discussion which gives different ideas on how to solve it. 这是他们对问题的解决方案 ,这是相应的讨论 ,针对如何解决这个问题给出了不同的想法。 Also interesting is their SafeLibraryHandle which I just found out about. 我刚刚发现的它们的SafeLibraryHandle也很有趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM