I'm trying to create a Python wheel that makes use of the BLAS and LAPACK C extensions. Compiling such package under Ubuntu requires of the following system packages:
libopenblas-dev
: (Open)BLAS development librariesliblapack-dev
: LAPACK development librariesliblapacke-dev
: C headers for LAPACKThis works nicely, but now I need to repeat the process under CentOS 5. The reason being I'm trying to create a manylinux wheel, and a recommended way seems to be using an old CentOS toolchain to guarantee it will work under different linux distributions.
The problem is, while libopenblas-dev
and liblapack-dev
have equivalences in CentOS 5 (openblas-devel
and lapack-devel
), there is no equivalent package for liblapacke-dev
. This makes some sense considering the LAPACK version provided in those packages is very old (3.0), which doesn't seem to support lapacke. But because of that I'm unable to compile my software, as gcc complains about missing lapacke.h headers.
Things I have tried:
--add-repo
option in yum-config-manager
, so I'm a bit at a loss here.lapacke is not supported in CentOS 5.0, so the C interface is not available, but you can still do the trick by calling the fortran symbols.
First, install CentOS packages for BLAS and LAPACK
yum install -y blas-devel lapack-devel
and add these libraries to the linker path
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/lib64"
Now you should be able to use BLAS and LAPACK functions in your C/C++ extensions code by importing the fortran symbols. For instance, to use the LAPACK function dpttrs
in the C++ source you would need to declare it as an external C symbol
extern "C" {
void dpttrs_(lapack_int* n, lapack_int* nrhs, const double* d, const double* e,
double* b, lapack_int* ldb, lapack_int *info );
}
and then it can be used normally by calling the dpttrs_
function.
Finally, when bundling the python package make sure to include the blas
and lapack
libraries and headers. For instance, when using cffi you should configure your sources in the following pattern
ffi.set_source(
'YOUR MODULE NAME',
"BASE SOURCES",
sources=sources,
source_extension='.cpp',
libraries=['blas', 'lapack'],
include_dirs=['/usr/include']
)