2009-08-06 1 views
0

:컴파일 C++ 코드 도끼 = 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/include/boost-numeric-bindings 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