我正在使用Cython,並且我想導入gnu科學C庫。使用cython結合gsl
#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
導入此模塊,但我得到了一個錯誤
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 Scientific Library 版本:1.16 Libs:-L/home/sulabh/gsl-1.16 /../ lib -l GSL $ {} GSL_CBLAS_LIB -lm -lm CFLAGS:-I /家庭/ sulabh/GSL-1.16 /../包括
任何人可以幫助
看看這個[post](http://stackoverflow.com/questions/24513246/wrapping-a-c-library-gsl-in-a-cython-code-by-using-callback)。這是如何在cython中調用gsl函數的一個例子。 – Dalek 2014-11-02 23:09:01