I have the .so file of a complex project written in C++. Is there a way I can use this library with python ? I'm not supposed to make any code changes to the existing C++ files. Is writing C++ wrapper around each file with boost.py the only way? Will the runtime of the code take a hit by doing this ?
2 Answers
Yes it's possible to call C++ code from Python with Boost.Python
.
The Boost Python Library is a framework for interfacing Python and C++. It allows you to quickly and seamlessly expose C++ classes functions and objects to Python, and vice-versa, using no special tools -- just your C++ compiler. It is designed to wrap C++ interfaces non-intrusively, so that you should not have to change the C++ code at all in order to wrap it, making Boost.Python ideal for exposing 3rd-party libraries to Python. The library's use of advanced metaprogramming techniques simplifies its syntax for users, so that wrapping code takes on the look of a kind of declarative interface definition language (IDL).

- 50,847
- 7
- 72
- 76
-
the question specifically says changing the c++ source code is impossible – AntiMatterDynamite Jul 16 '18 at 07:10
-
1Did you read the answer? It says *you should not have to change the C++ code at all*. – jspcal Jul 16 '18 at 07:11
-
Sure, but did you read the question? I presume OP knows it's possible to use Boost.Python ("*boost.py"). – rustyx Jul 16 '18 at 07:19
-
SWIG is an option: SWIG TUTORIAL
Although it can get quite frustrating to debug core dumps :)

- 163
- 7