Question

I am using Numeric Library Bindings for Boost UBlas to solve a simple linear system:

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

I tried compiling it with the following command:

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

but fail with the following error:

/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

What's wrong with my approach in the code?

Was it helpful?

Solution

sgesv_ is a symbol from LAPACK library, you'll have to link to that. uBLAS just binds to it I guess.

I too don't know the name of the library though :)

OTHER TIPS

Sorry if this is way off track, but I can't see you linking in the boost libraries in your g++ command. I see you including the search paths, but there's no explicit inclusion of the compiled Boost libraries themselves; something like -lboost (I'm afraid I don't know the exact format you'd need, and it may well depend on locations).

When linking with boost numeric binding library, you can link with the parameter


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

in gcc4


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

in gcc3

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top