编译和链接 Quantlib 需要一些时间,因为它不是一个小项目。我正在 Quantlib 之上构建一些附加功能,并且我想将这些附加功能保留在一个单独的项目中。
有没有一种方法可以通过 SWIG 轻松地将两个 C++ 项目公开到一个库中?因为我的项目很小,只有几个类,所以我可以轻松地手动完成 SWIG 自动化的工作。然而,我真的只想向我的用户部署最少的文件,即由 Quantlib-SWIG 构建的两个 dll。
Compiling and linking Quantlib takes some time, as it is not a small project. I am building some additional functionality on top of Quantlib, and I want to keep this additional functionality in a separate project.
Is there a way to easily expose two C++ projects into one library via SWIG? Because my project is quite small, just a few classes, I can easily afford to do manually what SWIG automates. However, I really want to deploy to my users only the bare minimum of files, that is the two dlls that are built by Quantlib-SWIG.
发布评论
评论(2)
我不太了解 Quantlib,但一般来说,使用 SWIG 执行此操作应该非常简单:SWIG 的 C# 模块支持 dllimport 选项,该选项允许您指定 P/Invoke 引用的 DLL方法(有关详细信息,请参阅 SWIG 手册的 C# 部分)。
因此,您只需为您的扩展创建一个单独的 SWIG 接口文件,将 dllimport 设置为 Quantlib 使用的名称,并将两个 C++ 粘合代码文件编译为 Quantlib 和您自己的代码的单个 DLL。
I don't know Quantlib in particular, but generally, doing this with SWIG should be quite straightforward: the C# module of SWIG supports the
dllimport
option which allows you to specify the DLL referenced for the P/Invoke methods (refer to the C# section of the SWIG manual for details).Thus, you can just create a separate SWIG interface file for your extension, set
dllimport
to the name used by Quantlib, and compile both C++ glue code files into a single DLL for both Quantlib and your own code.查看 Resolver Systems 的 带有 C# 绑定的 QuantLib,尽管我不确定他们保持最新 QuantLib 版本的频率。
它至少可以让您不必担心您的图书馆之一?
Take a look at Resolver Systems' pre-built binaries of QuantLib with C# bindings although I am unsure how frequently they keep it up to date with QuantLib releases.
It will save you having to worry about one of your libraries at least?