1

I want to use python code in C++ in an environment where we only have support for C++. It turns out that using python embedding, we can call python functions using C/C++. If I want to interpret python in C++, using python.h and libpython:

  1. Do I need to have python installed in the system to interpret the code at runtime?
  2. Can I use libpython as a static library, so it does not depend on any .so file?

I am looking for a minimal package of embedding that can run without a dynamic library and python environment.

taserghar
  • 340
  • 3
  • 15
  • 1
    Do I need to have python installed in the system to interpret the code at runtime?: that would defeat the purpose of having a standalone C++ program. So no. – Jean-François Fabre Nov 30 '22 at 05:56
  • 1
    Can I use libpython as a static library, so it does not depend on any .so file?: if you have a python static library available, you can use it. Else you're stuck. – Jean-François Fabre Nov 30 '22 at 05:57
  • @Jean-FrançoisFabre, "If you have a python static library?", what are the chances of not having libpython.a library? Will it be difficult to build the libpython's static library? I mean do I have to tweak the source code or makefiles, or it is already there, I can just grab it. – taserghar Nov 30 '22 at 06:01
  • 1
    I don't know. But you can build python statically https://wiki.python.org/moin/BuildStatically and then reuse the .a files. – Jean-François Fabre Nov 30 '22 at 06:07
  • this is probably a duplicate of this: https://stackoverflow.com/questions/8366544/can-i-statically-link-cython-modules-into-an-executable-which-embeds-python – Jean-François Fabre Nov 30 '22 at 06:09
  • 1
    Note that if you use an other Python modules (including the standard library) then you will need to have them and their dependencies installed. So your program has to be pretty minimal to be viably standalone – DavidW Nov 30 '22 at 07:26

0 Answers0