Here you can download a C wrapper for LAPACK.
The goals of this package are to take care of type compatibilities among languages and to expose to the user an interface that looks native in his programming language. To put it simply, the philosophy is that the user should not 'feel' the library language.
Hopefully, this package can someday be part of the official LAPACK release or at least help LAPACK moving in this direction.
0) Edit make.inc to fit your system Important things to change are : - ROOT_DIR : where make.inc is - BLASLIB : the blas library - LAPACKLIB : the lapack library - CBLASLIB : the cblas library - INCLUDE : you need to point to the cblas source directory. If you do not want to build the examples, just leave it blank. - LASRCDIR : lapack source directory, used by the script that generates the wrapper 1) Generate the c wrapper make source This will generate the .c files for every lapack function in src, and the .h in include. Will also generate the testing wrapper code in testing (more below). 2) Compile the c wrapper make library This will build lapack_wrapper.a in lib. 3) Compile and execute the test program make test This will build libtesting_wrapper_wrapper.a in testing, and execute the testing program.
To use the LAPACK c wrapper, just link your program with the lapack_wrapper.a library in the lib directory. The function names of the c functions are the name of the lapack routines, lowercase, with lapack_ in front of them (so, DGESV will be called by lapack_dgesv). The parameters obey the following rules : - complex and complex*16 are respectively, arrays of size 2 of float or double. - scalar input parameter that are not complex are passed by value. Other parameters are passed by adress. - A parameter that is a LOGICAL in Fortran is a long int in C. Just set it to 1 or 0, for .TRUE. or .FALSE. . If in any doubt, just have a look at the lapack_function.c, where function is the name of the subroutine you want to call. The code is really straightforward.
int n, k, lda, ldb, info; double *A, *b; /* malloc and initialization here */ lapack_dgesv( n, k, A, lda, ipiv, b, ldb, &info);
#include "../include/lapack_f77.h" #include "../include/lapack_enum.h" #include "../include/lapack_aux.h" void lapack_dgesv(const int n, const int nrhs, double * a, const int lda, int * ipiv, double * b, const int ldb, int * info ) { #ifdef F77_INT F77_INT F77_n=n, F77_nrhs=nrhs, F77_lda=lda, F77_ldb=ldb; int i_local; F77_INT F77_ipiv[n*1]; for(i_local=0;i_local<n*1;i_local++) { F77_ipiv[i_local]=(F77_INT) ipiv[i_local]; } F77_INT F77_info[1]; #else #define F77_n n #define F77_nrhs nrhs #define F77_lda lda #define F77_ipiv ipiv #define F77_ldb ldb #define F77_info info #endif f77_dgesv(&F77_n, &F77_nrhs, a, &F77_lda, F77_ipiv, b, &F77_ldb, F77_info); #ifdef F77_INT for(i_local=0;i_local<n*1;i_local++) { ipiv[i_local]=(int) F77_ipiv[i_local]; } info[0]=(int) F77_info[0]; #endif }