using C++ libraries in python using ctypes -


i have c++ library provides various classes managing data. have source code library. trying call function of lda.cpp of library python using ctypes. function in turn uses function other .cpp files in library.

//lda.cpp #include "model.h" #include <stdio.h> #include "lda.h"  int lda_est(double alpha, double beta) {     model lda;     if (lda.model_est(alpha, beta)) {          return 1;     }      lda.estimate();      return 0; } 

what found out need use c++ wrappers declaring functions extern , compile them .so file. question how should make wrapper file? , should declare functions in library extern or 1 want call python?

ctypes tool integrate existing libraries can't change. since have sources , willing change them, can write python module in c++, there multiple toolkits e.g. boost.python. in other words, @deleisha right, ctypes wrong tool job.

note can still create python module existing library wrapping functions , classes. using toolkit instead of extern "c" wrappers still makes sense there. firstly, eases wrapping classes , secondly, don't need extern "c" wrapper in c++ , ctypes wrapper in python.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -