Vote count:
0
I am trying to compile the following cython code : test_gsl.pyx
cdef extern from "math.h":
double log(double x) nogil
cdef extern from "gsl/gsl_math.h":
ctypedef struct gsl_function:
double (* function) (double x, void * params)
void * params
cdef extern from "gsl/gsl_integration.h":
ctypedef struct gsl_integration_workspace
gsl_integration_workspace * gsl_integration_workspace_alloc(size_t n)
void gsl_integration_workspace_free(gsl_integration_workspace * w)
int gsl_integration_qags(const gsl_function * f, double a, double b, double epsabs, double epsrel, size_t limit, gsl_integration_workspace * workspace, double *result, double *abserr)
cdef double do_callback(double x, void* params):
return (<MyCallback>params).eval(x)
cdef class MyCallback:
cdef double a
def __init__(self, a):
self.a = a
cpdef double eval(self, double x):
return self.a * log(x+1) * x
def call_gsl(self):
cdef gsl_integration_workspace* w =gsl_integration_workspace_alloc (1000)
cdef gsl_function F
F.function = &do_callback
F.params = <void*>self
cdef double result = 3, error = 5
gsl_integration_qags(&F, 0, 1, 0, 1e-7, 1000, w, &result, &error)
print result, error
gsl_integration_workspace_free(w)
So I have written a setup.py
script with given gsl libraries header directory and libgsl.so
and etc ..
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy
import sys
ext = Extension("test_gsl", ["test_gsl.pyx"],
include_dirs=[numpy.get_include(),
"/usr/include/"],
library_dirs=["/usr/lib/"],
libraries=["gsl"])
setup(ext_modules=[ext],
cmdclass = {'build_ext': build_ext})
The code gets compiled with this setup.py script even with the command line given as following:
cython test_gsl.pyx
gcc -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I /users/dapple/anaconda/pkgs/numpy-1.7.1-py27_2/lib/python2.7/site-packages/numpy/core/include/ -I /users/dapple/anaconda/include/python2.7/ -I /usr/include/ -c test_gsl.c -o test_gsl.so -lpython2.7 -lgsl -lgslcblas
but when I import the .pyx
or .so
in python it raises the following error message:
>>> import pyximport
>>> pyximport.install()
(None, <pyximport.pyximport.PyxImporter object at 0x7f9d54c5f0d0>)
>>> import test_gsl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/vol/anaconda/lib/python2.7/site-packages/Cython-0.20.1-py2.7-linux-x86_64.egg/pyximport/pyximport.py", line 431, in load_module
language_level=self.language_level)
File "/vol/anaconda/lib/python2.7/site-packages/Cython-0.20.1-py2.7-linux-x86_64.egg/pyximport/pyximport.py", line 210, in load_module
mod = imp.load_dynamic(name, so_path)
ImportError: Building module test_gsl failed: ['ImportError: /users/dalek/.pyxbld/lib.linux-x86_64-2.7/test_gsl.so: undefined symbol: gsl_integration_qags\n']
why the code couldn't access to the gsl_integration in C library??
asked 40 secs ago
Aucun commentaire:
Enregistrer un commentaire