I am trying to reproduce the work of Flavian Coelho related here . He used Cython and the Gnu Science Library (GSL) to get tremendous speedup over Python in random number generation. When I import compiled Cython code into Python (with the import cgibbs
), I get the following error:
ImportError: dlopen(./cgibbs.so, 2): Symbol not found: _gsl_rng_mt19937 Referenced from: /Users/wesley/scratch/cython/cgibbs.so Expected in: dynamic lookup
You will notice that the complaint is that the _gsl_rng_mt19937
symbol cannot be found. The function I'm trying to reference is called gsl_rng_mt19937
(there is no leading underscore), and that is how it appears in my .pyx
file. I think Cython is somehow causing the problem by adding this underline.
To facilitate troubleshooting, I removed the code and posted it below. My system: Mac OSX 10.7 (Lion), which runs Python 2.7.2 (32-bit), gcc-4.0 (which I used to compile GSL libraries in 32-bit form), GSL 1.15, and Cython v0.15.1.
Here is the contents of cgibbs.pyx:
#declaring external GSL functions to be used cdef extern from "math.h": double sqrt(double) cdef double Sqrt(double n): return sqrt(n) cdef extern from "gsl/gsl_rng.h": ctypedef struct gsl_rng_type: pass ctypedef struct gsl_rng: pass gsl_rng_type *gsl_rng_mt19937 gsl_rng *gsl_rng_alloc(gsl_rng_type * T) cdef extern from "gsl/gsl_randist.h": double gamma "gsl_ran_gamma"(gsl_rng * r,double,double) double gaussian "gsl_ran_gaussian"(gsl_rng * r,double) cdef gsl_rng *r = gsl_rng_alloc(gsl_rng_mt19937)
The error will disappear if I comment on the last line of my cgibbs.pyx
, but then I cannot use an external library ... Any insights you can offer are appreciated. Thanks!
source share