Compiling Quantlib via SWIG for C#

亡梦爱人 提交于 2019-11-27 22:33:21

So it would seem that the C# bindings for SWIG are available. One needs to browse the SVN repository or list of files on SouceForge to find them.

The SWIG folder contains several subfolders, depending on your language of choice, in my case C# was the one that interested me. You will need to download SWIG first and it the executable to system PATH variable.

Make sure to read the Readme.txt as it contains details about the QL_DIR environment variable that also needs to be created.

This may be a limitation of VS Express - but the solution file contains both the C# project and C++ project, of which only either the C# or C++ portions can be opened at any time. My suggestion would be to created separate solution files for the C++ and the C# projects.

Coming from a .Net background, lib files, obj files and the all the other jazz associated with c++ takes some time to getting use to.

Steps taken to get a working C# library

  1. Download QuantLib and Boost as described here
  2. Download the tar ball of the QuantLib-SWIG folder from SourceForge. Edit: There is a download of the zip available on the home page. Its listed within the subfolders. Check the v1.0 folders under Bindings
  3. Run the swig.cmd file located in QuantLib-SWIG\CSharp folder (you need to download SWIG first() --> this generates the cs wrapper files for Quantlib.
  4. Build the c++ project NQuantLibc - note the dll created here needs to be always shipped with the NQuantlib C# built dll. It needs to be placed in a location that is readable by the DLLImport attribute. (See Dynamic-Link Library Search Order on MSDN for list of locations)
  5. Build the C# project NQuantLib

With respect to my development environment, what would I need? It seems that the current version of QuantLib only builds with VS 2008. There have been some changes to VS 2010 which causes some issues with compilation. The C# project builds fine, however just remember to change the Target Framework from v4 to v3.5 to lower.

Note: As the time of writing this there was an issue with the QL_HEX_VERSION number in the source files of the C++ SWIG project. After running the swig.cmd open the VS project, and change Line 344 of quantlib_wrap.cpp to

#if QL_HEX_VERSION < 0x010001f0//0x010100f0

I have emailed the project author, and awaiting feedback. Edit: Luigi, correctly informed me that this is any issue with the code in SVN (which I used). He suggested that the QuantLib-SWIG-1.0.zip bindings should be used.

Quantlib also build on VC++ 2010 with the latest release.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!