简体   繁体   中英

python ctypes link multiple shared library with example gsl gslcblas

I want to use some functions from a shared library in python. From the python doc, I know ctypes is a good choice. However such library have some undefined symbols and I should link it to another shared library to get the symbols.

In g++, it is simple: g++ main.cpp -la -lb. The function I need is in liba.so, and liba.so has some undefined function which can be solved in libb.so.

But how to do that in ctypes? ctypes.cdll.LoadLibrary('liba.so') said that there are some undefined symbols, how to tell ctypes to find libb.so? Because ldd liba.so not show a link to libb.so.

Example: I want to use some functions in gsl. In g++:

g++ main.cpp -lgsl -lgslcblas

and ldd libgsl.so does not show a link to libgslcblas

In python:

ctypes.cdll.LoadLibrary('libgsl.so')

how to tell ctypes to find libgslcblas?

The same problem also happen if I use scalapack. I use ubuntu 16.04

This old answer tells to apply mode=ctypes.RTLD_GLOBAL , ie in this case

import ctypes

dll1 = ctypes.CDLL('libgslcblas.so', mode=ctypes.RTLD_GLOBAL)
dll2 = ctypes.CDLL('libgsl.so')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM