I have installed liblapacke-dev and liblapack-dev, and use find_package(LAPACK) and target_link_libraries(XXX PUBLIC LAPACK::LAPACK) to find and link them. However, the compiler complains that it cannot find LAPACKE_xxx during the linking process.
Here is a minimum working example:
// main.cc
#include "lapacke.h"
int main() {
LAPACKE_dgbsv(LAPACK_ROW_MAJOR,
1, 1, 1, 1, nullptr, 1, nullptr, nullptr, 1
);
}
#CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
project(test)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(LAPACK REQUIRED)
add_executable(main main.cc)
target_link_libraries(main LAPACK::LAPACK)
It seems that I need to find LAPACKE instead of LAPACK, but the problem is that I did not see any lapacke-config.cmake installed. How can I tell the compiler to find and link it?
You will need to add to your
target_link_librariesthe -llapacke option, like this:target_link_libraries(main LAPACK::LAPACK -llapacke)Otherwise, if you want to be fancier you can use the FindLAPACKE.cmake file that these people created: https://github.com/isl-org/Open3D/blob/master/3rdparty/cmake/FindLAPACKE.cmake
You will need to have a
cmake/directory within our build directory and append it to yourCMAKE_MODULE_PATHlike this:set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})Then you can use:
find_package(LAPACKE REQUIRED)and instead of using-llapackein yourtarget_link_librariesyou can uselapacke