用LAPACK库编译C ++程序

时间:2018-12-11 06:56:11

标签: c++ lapack

我是C ++编程的新手, 我有一个从互联网上获取的c ++代码。使用LAPACK库 我已经安装了LAPACK和BLAS(我希望安装成功)

:/usr/local/lib$ ls
libblas.a  liblapack.a  python3.6

程序是这个

#include <iostream>
#include "lapacke.h"

using namespace std;

int main()
{
    char    TRANS = 'N';
    int     INFO=3;
    int     LDA = 3;
    int     LDB = 3;
    int     N = 3;
    int     NRHS = 1;
    int     IPIV[3] ;

    double  A[9] = { 1, 2, 3, 2, 3, 4, 3, 4, 1 };

    double B[3] = {-4,-1,-2 };

    cout << "compute the LU factorization..." << endl << endl;
    LAPACK_dgetrf(&N,&N,A,&LDA,IPIV,&INFO);

    if(INFO)
    {
        cout << "solving the system..."<< endl << endl;
    }else{
        printf("solving the system...");
        dgetrs_(&TRANS,&N,&NRHS,A,&LDA,IPIV,B,&LDB,&INFO);
        if(INFO)
        {
            cout << "an error occured : "<< INFO << endl << endl;
        }else{
            cout << "print the result : {";
            int i;
            for (i=0;i<N;i++)
            {
                cout << B[i] << " ";
            }
            cout << "}" << endl << endl;
        }
    }

     cout << "program terminated." << endl << endl;
    return 0;
}

然后我尝试使用此命令对其进行编译

 g++ main.cpp -o run -llapack

但这是我得到的输出,

/usr/bin/ld: cannot find -llapack
collect2: error: ld returned 1 exit status

我正在使用Ubuntu 18.04 请帮我解决一下这个。 谢谢

1 个答案:

答案 0 :(得分:0)

听起来您的系统未设置为在/ usr / local / lib中搜索库。

您可以在编译命令中添加-L/usr/local/lib

如果需要安装该库,建议您使用以下命令:

sudo apt-get install liblapack-dev