将cython与gsl结合使用

时间:2014-11-02 22:40:07

标签: python c numpy cython gsl

我正在使用Cython,我想导入gnu科学C库。

#gsl_test.pyx

cdef extern from "gsl/gsl_math.h":
double gsl_pow_int (double x, int n)
def gibbs(double k, int t):    
y = gsl_pow_int (k, t)
return y

#setup.py 

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy

include_gsl_dir = "/home/sulabh/include/"
lib_gsl_dir = "/home/sulabh/lib/"


ext = Extension("sl", sources = ["gsl_test.pyx"],include_dirs=[numpy.get_include(),include_gsl_dir],library_dirs=[lib_gsl_dir],libraries=["gsl"])

setup(ext_modules=[ext],cmdclass = {'build_ext': build_ext})



python setup.py build_ext --inplace

which resulted into sl.o

我已经通过编写import sl进入python控制台导入此模块,但是我收到了错误

import sl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /home/sulabh/lib/libgsl.so.0: undefined symbol: cblas_dasum

这是我的包配置如何

prefix=/home/sulabh/gsl-1.16/..
exec_prefix=/home/sulabh/gsl-1.16/..
libdir=/home/sulabh/gsl-1.16/../lib
includedir=/home/sulabh/gsl-1.16/../include
GSL_CBLAS_LIB=-lgslcblas

名称:GSL 描述:GNU科学图书馆 版本:1.16 Libs:-L / home / sulabh / gsl-1.16 /../ lib -lgsl $ {GSL_CBLAS_LIB} -lm -lm Cflags:-I / home / sulabh / gsl-1.16 /../ include

任何人都可以提供帮助

1 个答案:

答案 0 :(得分:2)

将“gslcblas”添加到函数调用Extension中的库列表中,即

ext = Extension(...,libraries=["gsl", "gslcblas"])

或者您要添加的其他BLAS库。