2009-08-06 48 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