Wednesday, March 25, 2015

CBLAS compilation as a shared library

Reference CBLAS from Netlib compiles into static library (http://www.netlib.org/blas/blast-forum/cblas.tgz). I needed a shared library. 
First, you need to download and compile BLAS, since CBLAS is just C interface to Fortran BLAS:
wget http://www.netlib.org/blas/blas.tgz
tar xzvf blas.tgz
cd BLAS
make
It will produce static library "blas_LINUX.a".
Next, you need to download and configure CBLAS:
wget http://www.netlib.org/blas/blast-forum/cblas.tgz
tar xzvf cblas.tgz
cd CBLAS
Replace the corresponding variables in "Makefile.in" with:
BLLIB = /path_to_compiled_BLAS/blas_LINUX.a CBLIB = ../lib/cblas_$(PLAT).so
CFLAGS = -O3 -DADD_ -fPIC
FFLAGS = -O3 -fPIC
ARCH = gcc
ARCHFLAGS = -shared -o
Finally, make CBLAS:
make
It will produce shared library "cblas_LINUX.so".

6 comments:

  1. this worked for me:

    1. you need to have the BLAS from netlib:
    1.1. download latest version of the BLAS from here: http://www.netlib.org/blas/
    1.2. uncompress and got to the folder in the terminal and run make
    make
    1.3. look for the file named blas_LINUX.a and save the address to this file
    2. compile the netlib cblas
    2.1. download CBLAS from the same page
    2.2. uncompress
    2.3. open the file Makefile.in
    2.4. look for the line BLLIB = .../blas_LINUX.a
    2.5. put the address you had in step one here
    2.6. go to the terminal in unzipped cblas folder and run make
    3. look for the cblas.h file in the include folder and when you run the gcc link against this folder

    ReplyDelete
  2. I made a complete instructions and collected a lot of examples for BLAS, CBLAS, LAPACK, LAPACKE and CLAPACK here:
    https://github.com/Foadsf/Cmathtuts

    ReplyDelete
    Replies
    1. I got this error, which I could not fix, any suggestions?
      ../lib/libcblas.a: File format not recognised
      Makefile:238: recipe for target 'all' failed
      make[1]: *** [all] Error 1
      make[1]: Leaving directory '/home/ahmed/CBLAS/src'
      Makefile:147: recipe for target 'allprecision' failed
      make: *** [allprecision] Error 2

      Delete
  3. I got this error after typing 'make' for 'blas' :

    "gfortran -O3 -c isamax.f -o isamax.o
    make: gfortran: Command not found
    Makefile:171: recipe for target 'isamax.o' failed
    make: *** [isamax.o] Error 127"

    ReplyDelete
  4. ranlib: /lib/cblas_LINUX.so: File format not recognized

    I am getting this error after running make inside CBLAS.

    ReplyDelete