python下面通过ctypes模块调用c++库的方法
2016-12-22 20:10
696 查看
foo.cpp:#include <iostream>class Foo{public:void bar(){std::cout << "Hello" << std::endl;}};int test() {std::cout<<"hello world"<<std::endl;return 0;}extern "C" {Foo* Foo_new(){return new Foo();}void Foo_bar(Foo* foo){foo->bar();}int Test() {return test();}}通过 g++ -o libfoo.so -shared -fPIC foo.cpp 生产foo.sousec.pyfrom ctypes import cdlllib = cdll.LoadLibrary('./libfoo.so')#class Foo(object):# def __init__(self):# self.obj = lib.Foo_new()# def bar(self):# lib.Foo_bar(self.obj)lib.Test()#f = Foo()#f.bar() #and you will see "Hello" on the screen
注释掉的是调用c++类的方法,lib.Test()直接调用方法
相关文章推荐
- python下面通过ctypes模块调用c++库的方法
- python下面通过ctypes模块调用c++库的方法
- python下面通过ctypes模块调用c++库的方法
- python下面通过ctypes模块调用c++库的方法
- python下面通过ctypes模块调用c++库的方法
- python下面通过ctypes模块调用c++库的方法
- python下面通过ctypes模块调用c++库的方法
- python下面通过ctypes模块调用c++库的方法
- python下面通过ctypes模块调用c++库的方法
- python下面通过ctypes模块调用c++库的方法
- python下面通过ctypes模块调用c++库的方法
- python下面通过ctypes模块调用c++库的方法
- python下面通过ctypes模块调用c++库的方法
- python下面通过ctypes模块调用c++库的方法
- python下面通过ctypes模块调用c++库的方法
- python下面通过ctypes模块调用c++库的方法
- Linux下python如何调用c++的代码,用ctypes方法。。
- 关于python3调用C/C++的方法(ctypes)
- Python调用C语言的方法【基于ctypes模块】
- 在Python中通过threading模块定义和调用线程的方法