Linker Error using Boost

Volume I - Foundations

Linker Error using Boost

Postby misterweels » Mon Sep 10, 2012 3:38 am

I'm getting this weird Linker Error when I try to compile a simple code that multiplies matrices.



This version works

Code: Select all

#include <boost/numeric/ublas/matrix.hpp>



namespace ublas = boost::numeric::ublas;



typedef unsigned long myInt;



ublas::matrix<float> MatrixMultiply(ublas::matrix<float>A, ublas::matrix<float>B)

{

    myInt i, j, k;

    myInt rows = A.size1();

    myInt cols = B.size2();

    ublas::matrix<float> result(rows,cols);

    if (A.size2() == B.size1())

    {

        ublas::matrix<float> result(A.size1(), B.size2());

        for (i=0; i<A.size1(); i++) {

            for (j=0; j<B.size2(); j++) {

                float temp = 0;

                for (k=0; k<A.size2(); k++) {

                    temp += A(k,i)*B(j,k);

                }

                result(i,j) = temp;

            }

        }

    }

    return result;

}



int main(int argc, const char * argv[])

{

    ublas::matrix<float> A(2,2);

    A(0,0) = 1;

    A(0,1) = 2;

    A(1,0) = 3;

    A(1,1) = 4;

    MatrixMultiply(A,A);

   

    return 0;

}





But when I move the MatrixMultiply into a header and .cpp file I always get a linker error. I'm not sure what I'm doing wrong.



I'm using XCode to do all the compiling and coding.
misterweels
 
Posts: 6
Joined: Sun Jul 22, 2012 6:22 am

update

Postby misterweels » Mon Sep 10, 2012 5:54 am

I figured it out. I asked the question on stack overflow http://stackoverflow.com/questions/1234 ... brary-file



But now the question is why can't it work using namespace?
misterweels
 
Posts: 6
Joined: Sun Jul 22, 2012 6:22 am


Return to Introduction to the Boost C++ Libraries - Volume I (Demming/Duffy)

Who is online

Users browsing this forum: No registered users and 1 guest

cron