In the use of C programming, often call other software packages, where the Lapack,blas library is the most commonly used two libraries, here is the Linux system, the C language programming how to call these two libraries:
1. Let's start with the call to the Blas library, with two vector internal product functions as an example:
#include <stdio.h>#include<math.h>DoubleDdot_ (int*,Double*,int*,Double*,int*);intMain () {intn=2, incx=1, incy=1; Doublex[2]={1.0,1.0}; Doubley[2]={2.0,2.0}; Doublere; Re=ddot_ (&n, X, &incx, Y, &incy); printf ("The result is:%f\n", re); return 0;}
Compile the build target file:
Gcc-c Testddot.c-o TESTDDOT.O
To generate an executable file:
Gcc-o Testddot Testddot.o-lblas-lgfortran
Get results:
is:4.000000
Note: The Blas library is written in Gfortran, so you need to use the Gfortran library to generate the executable file, and need to link Blas library path, because I put the Blas library in the system default path, so here only need-lblas, otherwise, The path to the Blas library needs to be written out.
2. The following is a Lapack library call method, here to solve the linear equation group as an example.
#include <stdio.h>#include"lapacke.h"#defineM 2#defineN 2intMain () {intI, J, N=n, m=M; intinfo, ipiv[n]; DoubleA[m * n]= {1,2,4,2}; DoubleB[m*n] = {5,4,2.5,2}; Dgesv_ (&n, &n, A, &n, Ipiv, B, &n, &info); for(j=0; j<2*n; j + +) printf ("%f\t", B[j]); printf ("\ n"); return 0;}
Compile the build target file:
Gcc-o test_dgesv.o-c test_dgesv.c
To generate an executable file:
gcc- o test_dgesv test_dgesv.o -llapack -lblas
To run the program:
./TEST_DGESV
The results are as follows:
1.000000 1.000000 0.500000 0.500000
Note: The code in Blas and Lapack is written in Fortran, and the matrix in Fortran is stored by column, while the matrix in c is stored by row. Make sure you remember that when you're programmed.
Linux system C language calls Lapack, Blas Library