Accelerate LAPACKE
Unfortunately, Apple's Accelerate framework doesn't provide the LAPACKE C-interface library. Since MacOS 13.3 Ventura, the BLAS/LAPACK interface provided by Accelerate is recent enough to support the LAPACKE library.
This project uses Accelerate LAPACK to build the LAPACKE library against the Accelerate NEWLAPACK interface. More info on BLAS/LAPACK in Accelerate can be found there, too.
How to compile
It is recommended to use the Apple System C Compiler /usr/bin/cc
. You can also
use a more recent Clang compiler provided by Homebrew or MacPorts. If you have
other compilers installed on your system, make sure CMake finds the correct one.
Otherwise, help CMake by setting the environment variable $ export CC=/usr/bin/cc
in your terminal window.
It is also recommended to use at least CMake v3.25 with presets, but the CMake script also works down to CMake v3.12, if you set the required variables on the command line.
Prerequisites
Obviously, your operating system must be Mac OS X >=v13.3 Ventura with XCode installed. Additionally, you'll need the following software (easily obtainable via Homebrew or MacPorts):
- CMake
- Fortran compiler (e. g.
gfortran
contained in thegcc
package) to make it through the Reference LAPACK configure script
Workflow with CMake
Use the accelerate-lapacke32
preset (or the accelerate-lapacke64
preset for
the ILP64 interface) with CMake:
$ cmake --workflow --preset accelerate-lapacke32
This will configure LAPACKE to be installed in your ~/.local
directory by
default. If you prefer a different install location (e. g. /opt/custom
),
you can change it using a CMakeUserPresets.json
file, for which a template
file is provided:
$ cmake --workflow --preset user-accelerate-lapacke32
I wouldn't recommend installing to /usr/local
(used by Homebrew on Intel Macs)
or /opt/local
(used by MacPorts).
Analyzing the resulting .dylib
with otool
, you can see:
$ otool -L ./build/32/_deps/reference-lapack-build/lib/liblapacke.dylib
./build/32/_deps/reference-lapack-build/lib/liblapacke.dylib:
@rpath/liblapacke.3.dylib (compatibility version 3.0.0, current version 3.11.0)
/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1351.0.0)
Only the Accelerate framework and the System library are linked into the
.dylib
. No libgfortran
or other libraries are needed.
CMake v4 compatibility
To build the project with CMake v4 or higher, you must explicitly provide the
CMAKE_OSX_SYSROOT
variable in your CMakeUserPresets.json
. Both the
user-accelerate-lapacke32
and user-accelerate-lapacke64
presets should
additionally have the cache variable "CMAKE_OSX_SYSROOT": "macosx"
. This is
not included by default.
Using LAPACKE in another project
You can use your self-compiled LAPACKE library in other projects by importing
the CMake package in the other project's CMakeLists.txt
file:
find_package(LAPACKE CONFIG)
or
find_package(LAPACKE64 CONFIG)
and providing the above install location via the CMAKE_PREFIX_PATH
variable
from the command line:
$ cmake -S . -B ./build -D "CMAKE_PREFIX_PATH=~/.local"
This makes the imported lapacke
/lapacke64
shared library target available in
the other project's CMakeLists.txt
.