0

I have a C++ application needs to have a Python wrapper using ctypes.
There are many classes and their member functions were preceded by class names and scope resolution scope "::".

Does anybody know how to access their member functions using ctypes.

For example, one of the classes X and its member function is

extern "C" {
  void X::init(char*) {
    .....
  }
}

After the shared library is created, how to call X::init(...) in ctypes ?

Here is what I meant in python snippet below, it gave me error something like "undefined symbol init(), because I need to have class X specified but do not know how.

s = 'name'
lib = CDLL('./test.so')
lib.init.argtypes = c_char_p
lib.init.restype = None
lib.init(s)

Thanks.

user3658306
  • 217
  • 4
  • 15
  • `ctypes` wraps `C`. Try `SWIG` or `boost::Python`. – Mark Tolonen Jan 18 '15 at 04:51
  • Your question boils down to "how to import a C++ class using ctypes", for which you should be able to find answers easily. The scope resolution operator in this case is a red herring, it is only part of something that is way bigger, i.e. how classes are defined in C++. That said, the `extern "C"` is probably ignored by the compiler, because it simply doesn't apply to C++ classes. – Ulrich Eckhardt Jan 18 '15 at 08:16
  • possible duplicate of [How to use C++ classes with ctypes?](http://stackoverflow.com/questions/1615813/how-to-use-c-classes-with-ctypes) – Ulrich Eckhardt Jan 18 '15 at 08:17
  • @UlrichEckhardt Thanks for pointing out my problem. I would not use ctypes for C++ classes if I have an option. – user3658306 Jan 19 '15 at 19:43

0 Answers0