如何使用SWIG公开一个公共的内联c++方法
How do I use SWIG to expose a public inlined c++ method?
假设我有以下类:
class bar
{
public:
bar();
void helloworld(int date)
{ std::cout << "Hello world, the date is: " << date << std::endl; }
};
我必须在接口文件中做什么才能公开内联的helloworld()方法?我查看了%内联,但它似乎并没有达到我想要的效果,即将其公开为一个可调用的方法。
如有任何帮助,将不胜感激
你可以这样做:
/* bar_module.i */
%module bar_module
%{
#include "bar.h"
%}
%include "bar.h"
/* bar.h */
#include <iostream>
class bar
{
public:
bar();
void helloworld(int date)
{ std::cout << "Hello world, the date is: " << date << std::endl; }
};
/* bar.cc */
#include "bar.h"
bar::bar() {}
# test.py
import bar_module
bar_module.bar().helloworld(47)
# Build commands
swig -o bar_module_wrap.cc -python -c++ bar_module.i
g++ -o bar_module_wrap.os -c -fPIC -I/usr/include/python2.7 bar_module_wrap.cc
g++ -o bar.os -c -fPIC -I/usr/include/python2.7 bar.cc
g++ -o _bar_module.so -shared bar_module_wrap.os bar.os
# Test command
python test.py
# Output
Hello world, the date is: 47
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 运行同一解决方案的另一个项目的项目
- 挂起和取消挂起一个文件DLL
- 用C++中的一个变量定义一个常量
- 函数向量_指针有不同的原型,我可以构建一个吗
- 在c++中用vector填充一个简单的动态数组
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 预处理器:插入结构名称中的前一个行号
- 我在c++代码中生成了一个运行时#3异常
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 从链接列表c++中删除一个项目
- 告诉一个 const char 数组,除了编译时 C 样式的字符串外,它不以 '