Ayesha Kalra
Ayesha Kalra

Reputation: 173

Boost library simple compilation with tuples

Can anyone tell me why this works (compiles and runs)

#include <iostream>
#include <boost/numeric/ublas/matrix.hpp>
//#include <boost/tuple.hpp>
//#include <boost/tuple_comparison.hpp>
//#include <boost/tuple_io.hpp>
using namespace boost;

int main ( )
{
//  tuple<int, char, float> t(2, 'a', 0.9);
//  std::cout << t << std::endl;
    boost::numeric::ublas::matrix<double> m1;
     return 0;
 }

but when I uncomment the lines related to tuple, it says

boost_tuple.cpp:3:27: fatal error: boost/tuple.hpp: No such file or directory compilation terminated.

I use the following to compile in both cases:

g++ -Wall -c -I/usr/include/boost boost_tuple.cpp

And I also checked that /usr/include/boost/tuple.hpp exists

Upvotes: 1

Views: 4614

Answers (1)

karlphillip
karlphillip

Reputation: 93410

If you want to include it as:

#include <boost/tuple.hpp>

lose the boost part in -I/usr/include/boost. Right now this is being evaluated as /usr/include/boost/boost/tuple.hpp, which is probably your problem.

EDIT:

Make sure tuple.hpp is installed where you said it is, because on my system it's located in another folder: /usr/include/boost/tuple/tuple.hpp

Which means that I need to include the file as #include <boost/tuple/tuple.hpp> and compile it as:

g++ tuple.cpp -o tuple -I /usr/include/boost    

tuple.cpp:

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

using namespace boost;

int main ( )
{
    tuple<int, char, float> t(2, 'a', 0.9);
    boost::numeric::ublas::matrix<double> m1;

    return 0;
 }

Upvotes: 4

Related Questions