开发者

Converting QuantLib to QuantLib-SWIG C#

I have downloaded and built QuantLib (search google for quantlib and check install link) from their website in visual studio 2010. But because my knowledge of C++ is kind of minimal I would like to use SWIG so I can call the QuantLib libraries with C#. After the SWIG conversion I get a proper build. I thought this would run but at runtime I get the following error on multiple locations in the C# classes:

PInvokeStackImbalance was detected
A call to PInvoke function 'NQuantLib!QuantLib.NQuantLibcPINVOKE::new_Date__SWIG_1' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

MDA Error MSDN

I think that this is a general error so please let me know ho开发者_如何学Pythonw to fix this?


It might be some kind of version mismatch.

First: since you're using VC2010, I assume the version of QuantLib and QuantLib-SWIG you're using are checked out from Subversion; is this correct?

Second, did you use the VC2010 projects included in the checkout (the ones with _vc10 in the file name) for both QuantLib and QuantLib-C#, or did you convert other projects? Did you compile both in Release mode? And do the provided C# examples run from the IDE if you tell them to? (They're the EquityOption and BermudanSwaption projects)

Last, what version of SWIG are you using?


See http://www.resolversystems.com/products/quantlib-binary/ for a ready built version of QuantLib for C#.

I was up and running in a few minutes.


Please head to the quantlib extensions page for details on using QuantLib under other languages and platforms.


A temporary fix would be to create a configuration file (App.config) in the QuantLib_vc10 solution and add a NetFx40_PInvokeStackResilience element to suppress the unbalanced stack error.

I created the following App.config file and had this loaded into the BermudanSwaption_vc10 and EquityOption_vc10 projects.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <runtime>
        <NetFx40_PInvokeStackResilience enabled="1"/>
    </runtime>
</configuration>

Then the two projects will work fine, though probably with some cost in performance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜