gpt4 book ai didi

c++ - 通过 SWIG 从 Ruby 调用 Boost?

转载 作者:数据小太阳 更新时间:2023-10-29 08:13:51 26 4
gpt4 key购买 nike

假设我想从 Ruby 代码中调用一个或多个 boost 库函数。有很多我想这样做的例子,但最近我想使用 Boost Graph 库来进行高效的图形处理。我认为最常建议的方法是使用 SWIG。有没有人通过并为 Boost 库生成 SWIG 包装器?这实际上是与 Boost 互操作的最佳方式吗? Boost 的哪些部分无法通过 SWIG 访问,因为它们需要不受支持的 C++ 功能才能工作?

最佳答案

我不能说我已经专门为 Boost 库生成了包装器,但我已经为我自己的模板类生成了包装器。

这是完全可行的,只要您牢记 SWIG 将使用 %template 包装特定的模板实例化。指示。

如上面链接的文档所述:

[...] a bare C++ template does not define any sort of runnable object-code for which SWIG can normally create a wrapper. Therefore, in order to wrap a template, you need to give SWIG information about a particular template instantiation (e.g., vector<int>, array<double>, etc.). Second, an instantiation name such as vector<int> is generally not a valid identifier name in most target languages. Thus, you will need to give the template instantiation a more suitable name such as intvector when creating a wrapper.

使用指令你的 intvector看起来像这样:

%template(intvector) vector<int>;

关于c++ - 通过 SWIG 从 Ruby 调用 Boost?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4181629/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com