Boost logo

Boost Users :

Subject: [Boost-users] Newbie: Compiling multi filed programs
From: Pete (null_geodesic_at_[hidden])
Date: 2008-09-05 14:08:49


Still trying to get a grip on Boost with some toy problems. I have a very simple program that multiplies two vectors. It worked as a single file program, but doesn't work as a multi file program. I'm finding it difficult to deal with impressive looking templates in the compiler error messages. This is on Linux, g++, Debian testing.

09-prob.h:
=======
#pragma once

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

using namespace boost::numeric::ublas;

// n-vector outer product: |u><v|
template<class E1, class E2>
typename vector_matrix_binary_traits<E1, E2,scalar_multiplies<typename E1::value_type, typename E2::value_type> >::result_type
mult_vector_vector( E1 bra, E2 ket );

09-prob.cpp:
=========
#include "09-prob.h"

template<class E1, class E2>
typename vector_matrix_binary_traits<E1, E2,scalar_multiplies<typename E1::value_type, typename E2::value_type> >::result_type
mult_vector_vector( E1 bra, E2 ket )
{
   return outer_prod(bra, ket);
}

09-driver.cpp:
==========
#include "09-prob.h"
using std::cout;
using std::endl;

int main( void )
{
   using boost::numeric::ublas::vector; // Use Boost's vector, not STL's.
   vector<double> u(3), v(3);
   for( unsigned i = 0; i < u.size(); ++i ) {
      u(i) = static_cast<double>(i);
      v(i) = u(i) * u(i);
   }

   // Test mult_vector_vector
   //
   cout << mult_vector_vector(u, v) << endl;
   return 0;
}

And the error message:

g++ -g3 -Wall -Wextra -Waggregate-return -Wpointer-arith -Weffc++ -Wcast-qual -Wcast-align -Wmissing-declarations -Wredundant-decls -Wwrite-strings -Winline -c -o 09-driver.o 09-driver.cpp
g++ 09-prob.o 09-driver.o -o 09-prob
09-driver.o: In function `main':
/home/p/Baruch/numla/hw1/09-driver.cpp:29: undefined reference to `boost::numeric::ublas::vector_matrix_binary_traits<boost::numeric::ublas::vector<double, boost::numeric::ublas::unbounded_array<double, std::allocator<double> > >, boost::numeric::ublas::vector<double, boost::numeric::ublas::unbounded_array<double, std::allocator<double> > >, boost::numeric::ublas::scalar_multiplies<boost::numeric::ublas::vector<double, boost::numeric::ublas::unbounded_array<double, std::allocator<double> > >::value_type, boost::numeric::ublas::vector<double, boost::numeric::ublas::unbounded_array<double, std::allocator<double> > >::value_type> >::result_type mult_vector_vector<boost::numeric::ublas::vector<double, boost::numeric::ublas::unbounded_array<double, std::allocator<double> > >, boost::numeric::ublas::vector<double, boost::numeric::ublas::unbounded_array<double, std::allocator<double> > > >(boost::numeric::ublas::vector<double,
 boost::numeric::ublas::unbounded_array<double, std::allocator<double> > >, boost::numeric::ublas::vector<double, boost::numeric::ublas::unbounded_array<double, std::allocator<double> > >)'
collect2: ld returned 1 exit status
make: *** [09-prob] Error 1

Since 09-driver.o and 09-prob.o are being linked together, I'm guessing there's something wrong with the function signature?

Can some kind soul give me a few hints on how to make this work?

Thanks!

~

      


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net