I am declaring LAPACK functions inside a extern "C"
block and then using them in my C++ code. According to my limited understanding about how BLAS/LAPACK works, linking against my blas library should be enough. However, -lblas
does not suffice and I am forced to do -llapack
.
Why does this happen? I am using openblas
, hence -lblas
should be enough. What am I missing here? I would like to understand how does linking against BLAS/LAPACK work.
Minimal working exmaple:
#include <iostream>
extern "C" {
void dpptrf_(const char *, const int *, double *, int *);
}
int main() {
const char UPLO = 'L';
const int N = 3;
double AP[6] = {5,1,1,5,1,5};
int INFO = 0;
dpptrf_(&UPLO, &N, AP, &INFO);
for (auto elem : AP)
std::cout << elem << ", ";
return 0;
}
Reference to dpptrf:
Command to compile:
g++ main.cpp -lblas // Does not work
g++ main.cpp -lblas -llapack // Works
Additional information:
> pacman -Q blas
openblas 0.3.5-1
> pacman -Q lapack
lapack 3.8.0-2
> pacman -Q gcc
gcc 8.2.1+20181127-1