Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C++ Wrapper for python
#1
Hi I have a code written in python and I need use it with another code that is written in C++
it was recommended to me to have a c wrapper to link them butt I do not under stand how to do it. I am also do not know why I do not use a C++ wrapper.
The point is that I have some values that I need the other C++ code to read directly and feedback to python code.

as advice will be appreciated.
Reply
#2
I think you could try with the chapter about embedding python in another application in the official documentation.
Reply
#3
(Nov-06-2019, 05:14 PM)Gribouillis Wrote: I think you could try with the chapter about embedding python in another application in the official documentation.

Thank you for the link unfortunately it does not explain how it is done with C++ it only explain how the python code can be embedded into a C code.
Reply
#4
If you know how to embed Python into C and you know how to embed C into C++, won't it be enough to call python from C++? Call the C functions of the python API from the C++ program?
Reply
#5
Also look at CFFI written bye the mad scientist Evil of PyPy.
Using CFFI for embedding
CFFI Wrote:Possible use cases:
  1. Exposing a library written in Python directly to C/C++ programs.
  2. Using Python to make a “plug-in” for an existing C/C++ program that is already written to load them.
  3. Using Python to implement part of a larger C/C++ application (with static linking).
  4. Writing a small C/C++ wrapper around Python, hiding the fact that the application is actually written in Python (to make a
  5. custom command-line interface; for distribution purposes; or simply to make it a bit harder to reverse-engineer the application).
Reply
#6
(Nov-07-2019, 05:33 PM)Gribouillis Wrote: If you know how to embed Python into C and you know how to embed C into C++, won't it be enough to call python from C++? Call the C functions of the python API from the C++ program?

Is it better to embed c++ in python, or python in c++?
Reply
#7
kozaizsvemira Wrote:Is it better to embed c++ in python, or python in c++?

I have some experience calling C++ from python by using the SWIG interface generator. It is relatively easy to use. I would certainly feel better wrapping C++ from python than the reverse, but it is only my point of vue.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  SystemError: <method-wrapper '__getattribute__' of EnumMeta object sciloop 4 1,504 Jul-23-2022, 07:57 PM
Last Post: sciloop
  Using C++/CLI wrapper functions by Python Ales1000 2 1,766 Jun-21-2022, 04:50 AM
Last Post: Ales1000
  Python executable Script (Wrapper) Hwang 2 1,891 Jan-12-2022, 06:53 PM
Last Post: Hwang
  Sqla wrapper Slojure 1 1,533 Nov-01-2021, 04:36 PM
Last Post: Larz60+
  Python C++ wrapper problem JESuh 1 2,164 Mar-30-2021, 04:37 PM
Last Post: nilamo
  generating ctypes wrapper for a c library? brighteningeyes 9 7,062 Nov-04-2018, 02:31 AM
Last Post: brighteningeyes
  how to retrieve datas with Overpass API python wrapper apollo 0 2,908 Oct-15-2017, 02:27 PM
Last Post: apollo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020