2009-08-06 47 views
0

我使用Numeric Library Bindings for Boost UBlas解决一个简单 线性系统:编译的C++代码随着Boost的数字绑定库解决Ax = b的线性系统

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 

#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; 
} 

我试图用以下命令编译它

但失败,出现以下错误:

/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 

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

回答

3

sgesv_是来自LAPACK库的符号,您必须链接到该链接。我想,uBLAS只是绑定到它。

我也不知该库的名字虽然:)

+0

@Eugene:谢谢,你说得对。它适用于: 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 -llapack – neversaint 2009-08-06 04:48:58

1

对不起,如果这是偏离轨道,但我看不到你在g ++命令中的助推库链接。我看到你包括搜索路径,但没有明确包含已编译的Boost库本身;像-lboost(恐怕我不知道你需要的确切格式,这可能取决于地点)。

1

当升压数字绑定库链接,你可以用参数链接


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

在GCC4


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

in gcc3