James Bielman <jamesjb <at> jamesjb.com> writes:
/* available types */ GSL_VAR const gsl_interp_type * gsl_interp_cspline;
It looks like "gsl_interp_cspline" is a global variable, not a type, so you probably want to be doing something like:
(defcvar "gsl_interp_cspline" :pointer)
That should define a symbol macro *GSL-INTERP-CSPLINE* that will get the value of that C variable as a foreign pointer (I must admit, it seems a little weird to me to name the symbol macro with the special variable naming convention, since it's not actually special...)
James
This seems to work ! Thanks a lot. A quick and manual hack as a test is here (a bit ugly, but just for a start...)
(unless (find-package 'cffi) (asdf:oos 'asdf:load-op :cffi))
(defpackage :cffi-user (:use :common-lisp :cffi)) (in-package :cffi-user)
(pushnew #P"/usr/local/lib/" *foreign-library-directories* :test #'equal)
(define-foreign-library libgslcblas (:unix (:or "libgslcblas.so.0.0.0" "libgslcblas.so.0")) (t (:default "libgslcblas"))) (use-foreign-library libgslcblas)
(define-foreign-library libgsl (:unix (:or "libgsl.so.0.9.0" "libgsl.so.0")) (t (:default "libgsl"))) (use-foreign-library libgsl)
;;;; ;;;(defcfun "gsl_sf_bessel_J0" :double (x :double)) ;;;(time (format t "~A~%" (gsl-sf-bessel-J0 5d0)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; declare stuff (defcfun "gsl_interp_accel_alloc" :pointer)
(defcvar "gsl_interp_cspline" :pointer) (defcfun "gsl_spline_alloc" :pointer (ptr :pointer) (n :int))
(defcfun "gsl_spline_init" :int (ptr :pointer) (x :pointer) (y :pointer) (n :int))
(defcfun "gsl_spline_eval" :double (spla :pointer) (xi :double) (acca :pointer))
(defcfun "gsl_spline_free" :void (ptr :pointer))
(defcfun "gsl_interp_accel_free" :void (ptr :pointer))
;;; Main Starts here (defparameter *gsl-int-acc-alloc* (gsl-interp-accel-alloc)) (defparameter *gsl-spline-alloc* (gsl-spline-alloc *gsl-interp-cspline* 5))
(defparameter *xarray* (foreign-alloc :double :initial-contents '(1d0 2d0 3d0 4d0 5d0))) (defparameter *yarray* (foreign-alloc :double :initial-contents '(1d1 2d1 3d1 4d1 5d1)))
(gsl-spline-init *gsl-spline-alloc* *xarray* *yarray* 5) (format t "~A~%" (gsl-spline-eval *gsl-spline-alloc* 3.4d0 *gsl-int-acc-alloc*))
(foreign-free *xarray*) (foreign-free *yarray*)
(gsl-spline-free *gsl-spline-alloc*) (gsl-interp-accel-free *gsl-int-acc-alloc*)
Heiko