0

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

Rbruno
  • 11
  • 3

1 Answers1

0

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) 
Rbruno
  • 11
  • 3
  • What happens if you load the libraries in reversed order without *LAZYLOAD*? Also you're playing a dangerous game here, if one lib needs a symbol from another, it should link to that library (and automatically load it when itself is loaded), otherwise it might use a symbol (with the same name) that does something different. https://stackoverflow.com/questions/58631512/pywin32-and-python-3-8-0, although seems completely unrelated might solve your issue. – CristiFati Apr 21 '22 at 10:22
  • for my case only libc need libc2, and even in this order (which is the unlogical one) it is working just fine – Rbruno Apr 21 '22 at 12:22