Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create dynamic library (.so file) from Python code

Suppose I have a library written in Python that I'd like to call from a C software. Is there any way I can compile this Python code to a .so file?

like image 553
Mauren Avatar asked Apr 12 '14 22:04

Mauren


People also ask

Can Python use c++ dll?

Utilizing the ctypes module to call C/C++ functions in Python. “a foreign function library for Python. It provides C compatible data types, and allows calling functions in DLLs or shared libraries. It can be used to wrap these libraries in pure Python.”

How do I create a dynamic library?

To create a dynamic library in Linux, simply type the following command: gcc *. c -c -fPIC and hit return. This command essentially generates one object file .o for each source file .


1 Answers

This should help.

Also you can do both ways i.e. extend python by writing library in C and call it from Python code OR code functions in C that could be called from Python.

The standard term used (conceptually and help googling is "Python bindings"

Official reference from python docs

General reference - Integrating python with other languages

like image 87
fkl Avatar answered Sep 24 '22 12:09

fkl