How to call 2 linked shared library in python

402 Views Asked by At

I need to call C code (from xilinx IP model) in python 3. I made few test caling function from .so with ctypes library and it was successfull. But here I have an issue: the usefull library require 2 others .so files, I have no issue to build an exe but can't find any way of importing my final library in python.

Thanks for your help

1

There are 1 best solutions below

2
On

Consulting the forum i just found the solution: -when building .so , unresolved references are usual, dependencies are indicated when building the exe file -then to use 2 (or more ) dependant libraries .so in python a simple way to achieve it is:

RTLD_LAZY = 0x0001 #LAZYLOAD indicate that shared library called each others 
LAZYLOAD= RTLD_LAZY | RTLD_GLOBAL #for more information:  https://stackoverflow.com/questions/55724636/python-2-7-ctypes-circular-dependencies-of-so-shared-libraries 
libc = CDLL("Ccode.so",mode= LAZYLOAD)
libc2 = CDLL("lib1.so",mode= LAZYLOAD)