2009-08-06 3 views
0

コンパイルC++コードAx = bの線形システム私は、単純な 線形システムを解くために<a href="http://mathema.tician.de/node/391" rel="nofollow noreferrer">Numeric Library Bindings for Boost UBlas</a>を使用しています

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 /インクルード/ブースト数値バインディングsolve_Axb_byhand.cc -o solve_Axb_byhand -llapack – neversaint

1

申し訳ありませんが、これはオフトラックの場合ですが、g ++コマンドでブーストライブラリにリンクしているのを確認できません。私は検索パスを含めて見ていますが、コンパイルされたBoostライブラリ自体は明示的に含まれていません。 -lboostのようなものです(私はあなたが必要とする正確なフォーマットがわからず、場所に依存するかもしれません)。

1

をブースト数値結合ライブラリをリンクするときは、パラメータとリンクすることができますGCC4で


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


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

in gcc3

関連する問題