python ctypes link multiple shared library with example gsl gslcblas
<p>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.</p>

<p>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.</p>

<p>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.</p>

<p>Example: I want to use some functions in gsl. In g++: </p>

<pre><code>g++ main.cpp -lgsl -lgslcblas
</code></pre>

<p>and ldd libgsl.so does not show a link to libgslcblas</p>

<p>In python:</p>

<pre><code>ctypes.cdll.LoadLibrary('libgsl.so')
</code></pre>

<p>how to tell ctypes to find libgslcblas? </p>

<p>The same problem also happen if I use scalapack. I use ubuntu 16.04</p>

<p>This <a href="http://stackoverflow.com/a/30845750/5781248">old answer</a> tells to apply <code>mode=ctypes.RTLD_GLOBAL</code>, i.e. in this case</p>

<pre><code>import ctypes

dll1 = ctypes.CDLL('libgslcblas.so', mode=ctypes.RTLD_GLOBAL)
dll2 = ctypes.CDLL('libgsl.so')
</code></pre>

python linker ctypes gsl scalapack