Testing a C ++ Library with Python

I have a libfoo.so library created from C ++ code (compiled using gcc), and I would like to quickly test some of its exported classes (basically creating an instance of the class and then calling its methods to check the output).

So far I could do it in C / C ++ with a main file that references the appropriate library and build my tests, but I think it would be much easier if you could just call Python from the command line and call methods from there .

I know that I can use CDLL from ctypes to load C-style libraries, but is there any similar functionality for C ++ libraries and objects?

EDIT: Ideally, I do not want to change the C ++ code, I will need to use it as is.

+3
source share
2 answers

I agree with Chris. However, I want to note that Cython supports C ++ (with some limitations).

+2
source

Honestly, C ++ is a bit messy. You can do something like create a pure C function that wraps C ++ functionality (which you call from python), but at this point you can write your tests in C ++. Unfortunately, the only tool for this (that I know) is SWIG.

, "" , . (, JUST ints , , char *), . swig, , . , , API CPython, .

CPython SWIG. , , API . , . , , C/++.

( )

+8

All Articles