0

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:

netlib.org/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
enanone
  • 923
  • 11
  • 25
  • 1
    _"According to my limited understanding about how BLAS/LAPACK works, linking against my blas library should be enough."_ Why do you think so? It obviosly depends on the lapack library. – πάντα ῥεῖ Apr 19 '19 at 12:57
  • You are right. `nm -DC libblas.so | grep dpptrf` produces no results, whereas `nm -DC liblapack.so | grep dpptrf` has the symbol. I guess this question can be closed/removed – enanone Apr 19 '19 at 13:30
  • Don't worry, your question is already closed righteously. – πάντα ῥεῖ Apr 19 '19 at 13:31

0 Answers0