0

我正在使用Boost 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

我在代码中的方法有什么问题?

4

3 回答 3

3

sgesv_ 是 LAPACK 库中的一个符号,您必须链接到它。我猜 uBLAS 只是绑定到它。

不过我也不知道图书馆的名字:)

于 2009-08-06T04:06:11.193 回答
1

与boost数值绑定库链接时,可以用参数链接


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

在 gcc4 中


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

在 gcc3 中

于 2009-12-02T03:35:18.760 回答
1

抱歉,如果这偏离了轨道,但我看不到您在 g++ 命令中的 boost 库中链接。我看到您包括搜索路径,但没有明确包含已编译的 Boost 库本身;-lboost 之类的东西(恐怕我不知道您需要的确切格式,它很可能取决于位置)。

于 2009-08-06T03:36:18.743 回答