1

I have successfully extended my python code in C following this:

Call a Python function from within a C program

I have compiled the code and created a .dll. However, when I opened it with the dependencywalker I have seen that it still requires the python code. I want the dll to be standalone, so it doesn't depend on the script .py. I thought that using the tag -static in g++ would be enough but it doesn't work for me.

Alex
  • 3,111
  • 6
  • 27
  • 43
Jonw3
  • 23
  • 4

1 Answers1

2

The Python documentation has a chapter on Extending and Embedding Python with C.

With good enough coding conventions this can by applied to C++ code. You will use extern "C" to declare functions coded in C++ callable from C.

Be careful to avoid throwing a C++ exception to Python code.

On Linux, see also dlopen(3) and dlsym(3) and the C++ dlopen mini howto.

Python is open source. You should consider downloading its C source code and studying it.

Be aware of the GIL in Python. Multi-threading C++ code will be tricky.

Consider also generating C or C++ code with tools like RefPerSys or ANTLR, or writing in Python your C or C++ code generator.

Perhaps use static source code analyzers (like Frama-C or Bismon) on your C source code.

Be aware that C and C++ are different programming languages. See this and n1570 and n3337 or better.

PS. For Bismon or RefPerSys please contact me by email to basile@starynkevitch.net and basile.starynkevitch@cea.fr, but mention the URL of your question here in your email.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547