Linux那点事
来源:互联网 发布:origin怎么导入数据 编辑:程序博客网 时间:2024/06/02 05:32
最近用到Linux比较多 所以需要恶补一下 。。。。
说一下最近的工作内容吧 ,很简单 使用swig 封装C++函数 生成供python调用的模块 就这些。。。
swig 说白了就是一个封装的工具 它会根据写好的c/c++ 的函数代码生成一个封装代码 然后 将封装代码 与 c/c++ 函数代码共同编译链接 最后生成供python调用的模块(其实我看来就是给原来的c/c++函数套了一个python认识的面具而已)
我用了以下几步:
- swig -python -c++ animal.i 生成了 hello_wrap.cxx 和 hello.py
- g++ -fpic -c animal_wrap.cxx animal.cpp 生成了 animal_wrap.o animal.o
- g++ -shared animal_wrap.o animal.o -o _animal.so 生成了 _animal.so
1 /*file:animal.cpp*/ 2 #include<iostream> 3 using namespace std; 4 class Animal{ 5 public: 6 int eyes; 7 int mouth; 8 int nose; 9 }; 10 int func(){ 11 Animal Dog; 12 Dog.eyes = 2; 13 Dog.mouth = 1; 14 Dog.nose = 1; 15 cout << "Dog's eyes have " << Dog.eyes << endl; 16 cout << "Dog's mouth has " << Dog.mouth << endl; 17 cout << "Dog's nose has " << Dog.nose << endl; 18 return 0; 19 }
1 /*file:animal.h*/ 2 int func();
1 /*file:animal.i*/ 2 %module animal 3 %{ 4 #include "animal.h" 5 %} 6 int func();
1 ##file:test.py 2 import animal 3 a=animal.func() 4 print a
[boy@localhost src]$ python test.py Dog's eyes have 2Dog's mouth has 1Dog's nose has 1
这就是最基本的swig 封装 以及python调用
1 0
- Linux那点事
- Linux那点事
- Linux rm 那点事
- linux 多线程那点事
- 读linux usb那点事记录
- Linux下线程编程那点事
- Linux的man那点事
- linux管道的那点事
- linux管道的那点事
- 转载:linux管道的那点事
- linux管道的那点事
- *20161106*关于Linux的那点事
- linux管道的那点事
- linux管道的那点事
- 面试那点事
- 公司那点事
- 编程那点事!!
- 公务员那点事
- 栈解旋unwinding
- HDU1560 DNA sequence 迭代深搜IDA*
- Hdu 3549 Flow Problem(最大流)
- 素数------有无穷多个素数(1)
- 王小二切饼
- Linux那点事
- 1.14
- 联接excel 两列数据,按值对应
- 笔记:QT多线程编程步骤(其一)
- java学习-基础(6)
- 问题十七:怎么用ray tracing画多个球?
- QQ分享本地图片给好友
- HttpURLConnection—多用途、轻量极的HTTP客户端
- PM的烦恼---转版本!