我使用数字库绑定时升压的uBLAS 以解决一个简单的 线性系统:

#include<boost/numeric/ublas/matrix.hpp>
#include<boost/numeric/ublas/io.hpp>
#include<boost/numeric/bindings/traits/ublas_matrix.hpp>
#include<boost/numeric/bindings/lapack/gesv.hpp>
#include <boost/numeric/bindings/traits/ublas_vector2.hpp>


namespace ublas = boost::numeric::ublas;
namespace lapack= boost::numeric::bindings::lapack;


int main()
{
    ublas::matrix<float,ublas::column_major> A(3,3);
    ublas::vector<float> b(3);


    for(unsigned i=0;i < A.size1();i++)
        for(unsigned j =0;j < A.size2();j++)
        {
            std::cout << "enter element "<<i << j << std::endl;
            std::cin >> A(i,j);
        }

    std::cout << A << std::endl;

    b(0) = 21; b(1) = 1; b(2) = 17;

    lapack::gesv(A,b);

    std::cout << b << std::endl;


    return 0;
}

我试图用以下命令编译它:

g++ -I/home/foolb/.boost/include/boost-1_38 -I/home/foolb/.boostnumbind/include/boost-numeric-bindings solve_Axb_byhand.cc -o solve_Axb_byhand

但失败,出现以下错误:

/media/disk/tmp/ccbd973l.o: In function `boost::numeric::bindings::lapack::detail::gesv(int, int, float*, int, int*, float*, int, int*)':
solve_Axb_byhand2.cc:(.text._ZN5boost7numeric8bindings6lapack6detail4gesvEiiPfiPiS4_iS5_[boost::numeric::bindings::lapack::detail::gesv(int, int, float*, int, int*, float*, int, int*)]+0x59): undefined reference to `sgesv_'
collect2: ld returned 1 exit status

这有什么错我的代码的方法呢?

有帮助吗?

解决方案

sgesv_是LAPACK库中的元件,你必须链接到。的uBLAS只是结合到它,我想。

我也不知该库的名称,但:)

其他提示

很抱歉,如果这是这样偏离了轨道,但我看不到你在你的G ++命令Boost库链接。我看你,包括搜索路径,但有编译Boost库本身没有明确列入;像-lboost(恐怕我不知道你需要的确切格式,并且很可能取决于位置)。

当与升压数字结合库链接,可以用参数链接


-Lpath/to/lapack -llapack -Lpath/to/blas -lblas -lgfortran

在GCC4


-Lpath/to/lapack -llapack -Lpath/to/blas -lblas -lg2c

在的gcc3

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top