简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM