opencv: Building against OpenBLAS complains about missing lapacke.h
System information (version)
- OpenCV => 3.3.1
- Operating System / Platform => Ubuntu 16.04. (xenial)
Detailed description
It is not possible to build openCV against libOpenBLAS unless one also installs an additional LAPACK implementation that includes the lapacke.h
header, e.g. liblapacke-dev
on Ubuntu.
To me that does not look like the intended behavior and it might be explained by the fact, that OpenBLAS on Ubuntu only include cblas.h
and f77blas.h
as an header.
On the other hand OpenCVFindOpenBLAS.cmake
does not check for lapacke.h
, so it might just be the case that ocv_lapack_check()
is too strict when it comes to OpenBLAS.
@alalek You seem to have some experience with this. Any thoughts on this?
Steps to reproduce
If I only install libopenblas-dev
, I get the following cmake output once ocv_lapack_check()
inside OpenCVFindLAPACK.cmake
is called:
-- LAPACK(OpenBLAS): LAPACK_LIBRARIES: /usr/lib/libopenblas.so
CMake Warning at cmake/OpenCVFindLAPACK.cmake:29 (message):
LAPACK(OpenBLAS): CBLAS/LAPACK headers are not found in '/usr/include'
Call Stack (most recent call first):
cmake/OpenCVFindLAPACK.cmake:155 (ocv_lapack_check)
CMakeLists.txt:596 (include)
If I now install any LAPACK implementation that includes a lapacke.h
, e.g.: liblapacke-dev
, everything passes and OpenBLAS will be used:
-- LAPACK(OpenBLAS): LAPACK_LIBRARIES: /usr/lib/libopenblas.so
-- LAPACK(OpenBLAS): Support is enabled.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 8
- Comments: 23 (3 by maintainers)
Even installing of liblapacke-dev from the repository did not work for me (Opencv 3.4)
liblapacke-dev Installed lapacke.h to /usr/include/lapacke.h OpenCVFindLAPACK.cmake complains not found it in ‘/usr/include/openblas’
My current workaround is to copy /usr/include/lapacke*.h to ‘/usr/include/openblas’, then verything works fine
On Linux mint 18, equal to ubuntu 16.04
BLAS is API with functions for low-level matrix/vector operations (like gemm). OpenCV requires LAPACK API too (high-level functionality, like matrix factorization, eigenvalues, etc): http://www.netlib.org/lapack/
For some reason, CMake’s FindLAPACK module doesn’t provide any information about header files (they are required for C/C++ programs compilation).
Ubuntu’s OpenBLAS binaries support LAPACK API symbols.
But headers are not provided for LAPACK routines via “-dev” package (only BLAS headers are available). (update: new link on Ubuntu 18.04 because 16.04 is EOL)
BTW, Fedora provides “openblas-devel” package with lapacke.h header:
OpenCV detects OpenBLAS on Fedora (if there is no other conflicted BLAS/LAPACK libraries):
OpenBLAS source repository has LAPACK files internally. I have no idea why LAPACK headers are not packaged on Ubuntu. We use
liblapacke-dev
workaround at this moment on our Ubuntu builders.I ran into this issue as well, and I have developed a solution.
The fix involves three steps:
lapack-netlib/LAPACKE/include/*.h
files into theinclude
directory where OpenBLAS is installed (location ofcblas.h
,f77blas.h
,openblas_config.h
, i.e. CMakeOpenBLAS_INCLUDE_DIR
)liblapacke.a
into thelib
directory where OpenBLAS is installed (location oflibopenblas.so
, etc, i.e. CMakeOpenBLAS_LIB
)-D LAPACK_LIBRARIES=/path/path/to/liblapacke.a
, where/path/path/to/
should matchOpenBLAS_LIB
In case they are useful to anyone, here are my scripts for a custom install from source using custom compilers.
As a side note, OpenCV should really focus some resources on fixing its ridiculous dependencies situation. I’ve probably spent more time over the years compiling and configuring the latest version than writing OpenCV code. As far as I can tell, there isn’t even an install readme or dependency doc anymore. If you look at the CMake statement above, I have to turn off Python and Java like seven different times and CMake still lists the path to the Python interpreter in the output.
Perhaps we should drop
OpenCVFindAtlas.cmake
OpenCVFindOpenBLAS.cmake
scripts and use CMake official instead (available since CMake 2.6.0): https://gitlab.kitware.com/cmake/cmake/blob/v3.11.3/Modules/FindBLAS.cmakeTo me this currently looks more like a packaging bug in Ubuntu. That is why I submitted the problem to their Launchpad bug tracker. Please feel free to mark yourself as affected, to increase visibility:
https://bugs.launchpad.net/ubuntu/+source/openblas/+bug/1728068
I’m trying to build on an aarch64 machine on Ubuntu, and just installing
liblapacke-dev
didn’t work for me.The problem seems to be that
liblapacke-dev
putslapacke.h
at/usr/include/lapacke.h
, but cmake is searching in/usr/include/aarch64-linux-gnu
.I tried passing
-DLAPACKE_INCLUDE_DIR=/usr/include
, but that didn’t help because on line 98 that gets overwritten with the OpenBLAS include directory.My solution was to pass
-DOpenBLAS_INCLUDE_DIR='/usr/include/aarch64-linux-gnu;/usr/include'
instead of-DOpenBLAS_INCLUDE_DIR=/usr/include/aarch64-linux-gnu
.The workaround didn’t entirely do it for me (I’m on Ubuntu 17.10, installing OpenCV 3.4.1). I did the workaround and added cblas header
cblas.h
:I edited cmake/OpenCVFindOpenBLAS.cmake and added the line
to the
Open_BLAS_LIB_SEARCH_PATHS
list. This solved the issue!I think there are three problems:
OpenCVFindLAPACK.cmake
module looks under only one folder whereOpenCVFindOpenBLAS.cmake
foundcblas.h
.cblas.h
on Ubuntu 17.x. (It’s in/usr/include/x86_64-linux-gnu
)libopenblas.so
on Ubuntu 17.x (It’s in/usr/lib/x86_64-linux-gnu
)Using ubuntu 17.10:
Installed packages