I created a program using boost for extracting python variables and lapack for solving matrix. However I have some trouble in compilation process
Here are my includes and the firsts line of code :
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include "lapacke.h"
#include <math.h>
#include <omp.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include <sys/times.h>
#include <exception>
#include <fstream>
#include <iostream>
#include <cassert>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <limits>
#include <Python.h>
#include <arrayobject.h>
#include <boost/timer/timer.hpp>
#include <boost/python.hpp>
#include "boost/python/extract.hpp"
using namespace std;
The compilation results in a large amount of errors that I have difficulties to interpret this output.
Here is a sample :
In file included from /usr/include/c++/4.9/complex.h:36:0,
from /usr/include/lapacke.h:73,
from /project/git/CLCCD/whittaker/wfilter.cpp:4:
/usr/include/boost/operators.hpp:308:26: error: expected identifier before ‘(’ token
template <class T, class I, class R, class B = ::boost::detail::empty_base<T> >
^
/usr/include/boost/operators.hpp:308:26: error: expected ‘)’ before ‘__extension__’
template <class T, class I, class R, class B = ::boost::detail::empty_base<T> >
^
/usr/include/boost/operators.hpp:308:26: error: expected ‘>’ before ‘__extension__’
/usr/include/boost/operators.hpp:308:26: error: expected unqualified-id before ‘)’ token
template <class T, class I, class R, class B = ::boost::detail::empty_base<T> >
^
In file included from /usr/include/boost/system/error_code.hpp:17:0,
from /usr/include/boost/chrono/detail/system.hpp:12,
from /usr/include/boost/chrono/system_clocks.hpp:64,
from /usr/include/boost/chrono/chrono.hpp:13,
from /usr/include/boost/timer/timer.hpp:14,
from /project/git/CLCCD/whittaker/wfilter.cpp:37:
/usr/include/boost/operators.hpp:649:7: error: ‘indexable’ was not declared in this scope
, indexable<T, D, R, B
^
/usr/include/boost/operators.hpp:650:7: error: wrong number of template arguments (6, should be 3)
> > > > {};
^
/usr/include/boost/operators.hpp:420:8: error: provided for ‘template<class T, class U, class B> struct boost::additive2’
struct additive2
^
/usr/include/boost/operators.hpp:650:9: error: template argument 2 is invalid
> > > > {};
^
/usr/include/boost/operators.hpp:650:11: error: template argument 3 is invalid
> > > > {};
^
/usr/include/boost/operators.hpp:650:13: error: expected ‘{’ before ‘>’ token
> > > > {};
^
/usr/include/boost/operators.hpp:650:13: error: expected unqualified-id before ‘>’ token
/usr/include/boost/operators.hpp:851:1: error: ‘indexable’ is not a member of ‘boost’
BOOST_OPERATOR_TEMPLATE3(indexable)
^
/usr/include/boost/operators.hpp:851:1: error: ‘indexable’ is not a member of ‘boost’
/usr/include/boost/operators.hpp:851:1: error: wrong number of template arguments (4, should be 1)
BOOST_OPERATOR_TEMPLATE3(indexable)
^
/usr/include/boost/operators.hpp:731:26: error: provided for ‘template<class T> struct boost::is_chained_base’
template<class T> struct is_chained_base {
^
/usr/include/boost/operators.hpp:851:1: error: expected unqualified-id before ‘>’ token
BOOST_OPERATOR_TEMPLATE3(indexable)
^
In file included from /usr/include/c++/4.9/complex.h:36:0,
from /usr/include/lapacke.h:73,
from /project/git/CLCCD/whittaker/wfilter.cpp:4:
/usr/include/boost/smart_ptr/detail/spinlock_pool.hpp:34:15: error: expected ‘)’ before ‘__extension__’
template< int I > class spinlock_pool
^
/usr/include/boost/smart_ptr/detail/spinlock_pool.hpp:34:15: error: expected ‘>’ before ‘__extension__’
/usr/include/boost/smart_ptr/detail/spinlock_pool.hpp:34:15: error: expected unqualified-id before ‘)’ token
template< int I > class spinlock_pool
^
/usr/include/boost/smart_ptr/detail/spinlock_pool.hpp:75:15: error: expected ‘)’ before ‘__extension__’
template< int I > spinlock spinlock_pool< I >::pool_[ 41 ] =
^
/usr/include/boost/smart_ptr/detail/spinlock_pool.hpp:75:15: error: expected ‘>’ before ‘__extension__’
/usr/include/boost/smart_ptr/detail/spinlock_pool.hpp:75:15: error: expected unqualified-id before ‘)’ token
template< int I > spinlock spinlock_pool< I >::pool_[ 41 ] =
^
// some other lines ...
In file included from /usr/include/boost/shared_ptr.hpp:17:0,
from /usr/include/boost/python/converter/shared_ptr_to_python.hpp:10,
from /usr/include/boost/python/converter/arg_to_python.hpp:15,
from /usr/include/boost/python/call.hpp:15,
from /usr/include/boost/python/object_core.hpp:14,
from /usr/include/boost/python/args.hpp:25,
from /usr/include/boost/python.hpp:11,
from /project/git/CLCCD/whittaker/wfilter.cpp:38:
/usr/include/boost/smart_ptr/shared_ptr.hpp: In function ‘boost::shared_ptr<T> boost::atomic_load(const boost::shared_ptr<T>*)’:
/usr/include/boost/smart_ptr/shared_ptr.hpp:954:5: error: ‘spinlock_pool’ is not a member of ‘boost::detail’
boost::detail::spinlock_pool<2>::scoped_lock lock( p );
^
/usr/include/boost/smart_ptr/shared_ptr.hpp:954:36: error: ‘::scoped_lock’ has not been declared
boost::detail::spinlock_pool<2>::scoped_lock lock( p );
^
/usr/include/boost/smart_ptr/shared_ptr.hpp: In function ‘void boost::atomic_store(boost::shared_ptr<T>*, boost::shared_ptr<T>)’:
/usr/include/boost/smart_ptr/shared_ptr.hpp:965:5: error: ‘spinlock_pool’ is not a member of ‘boost::detail’
boost::detail::spinlock_pool<2>::scoped_lock lock( p );
^
/usr/include/boost/smart_ptr/shared_ptr.hpp:965:36: error: ‘::scoped_lock’ has not been declared
boost::detail::spinlock_pool<2>::scoped_lock lock( p );
^
// and it continues...
Q : My limited knowledge on compilation tends to suppose a conflict between lapack and boost, but how to resolve ?
Q : Is this a problem related to any namespace defined in cpp file ?
In fact this was a problem in includes order...
by putting #include "lapacke.h" after boost includes, it solved the things...
I'm having other problems now... but that's another story...
Related
I found the following class definition in the boost library 1.71.0 which is installed at /usr/include/boost in my case.
class BOOST_SYMBOL_VISIBLE seconds : public time_duration
{
public:
template <typename T>
explicit seconds(T const& s,
typename boost::enable_if<boost::is_integral<T>, void>::type* = BOOST_DATE_TIME_NULLPTR) :
time_duration(0,0, numeric_cast<sec_type>(s))
{}
};
The Above class definition can be found out at /usr/include/boost/date_time/posix_time/posix_time_duration.hpp
I am using following code-snippet where the class boost::posix_time::seconds is instantiated:
#include <boost/asio.hpp>
#include <boost/array.hpp>
#include <boost/format.hpp>
#include <boost/bind.hpp>
#include <boost/serialization/access.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/shared_array.hpp>
#include <boost/algorithm/string.hpp>
#include <chrono>
#include <vector>
#include <boost/date_time/posix_time/posix_time_duration.hpp>
int main()
{
boost::asio::io_service io_service;
boost::asio::ip::tcp::socket socket(io_service);
boost::asio::deadline_timer timer(io_service);
timer.expires_from_now(boost::posix_time::seconds(60.0))
return 0;
}
Let's say I save the above code-snippet with the file name boost.cpp. Then I compile boost.cpp using the command
g++ -I /usr/include/boost -pthread boost.cpp
However, I am getting the following error:
boost.cpp: In function ‘int main()’:
boost.cpp:19:59: error: no matching function for call to ‘boost::posix_time::seconds::seconds(double)’
19 | timer.expires_from_now(boost::posix_time::seconds(60.0))
| ^
In file included from /usr/include/boost/date_time/posix_time/posix_time_types.hpp:16,
from /usr/include/boost/asio/time_traits.hpp:23,
from /usr/include/boost/asio/detail/timer_queue_ptime.hpp:22,
from /usr/include/boost/asio/detail/deadline_timer_service.hpp:29,
from /usr/include/boost/asio/basic_deadline_timer.hpp:24,
from /usr/include/boost/asio.hpp:25,
from boost.cpp:1:
/usr/include/boost/date_time/posix_time/posix_time_duration.hpp:57:16: note: candidate: ‘template<class T> boost::posix_time::seconds::seconds(const T&, typename boost::enable_if<boost::is_integral<T>, void>::type*)’
57 | explicit seconds(T const& s,
| ^~~~~~~
/usr/include/boost/date_time/posix_time/posix_time_duration.hpp:57:16: note: template argument deduction/substitution failed:
/usr/include/boost/date_time/posix_time/posix_time_duration.hpp: In substitution of ‘template<class T> boost::posix_time::seconds::seconds(const T&, typename boost::enable_if<boost::is_integral<T>, void>::type*) [with T = double]’:
boost.cpp:19:59: required from here
/usr/include/boost/date_time/posix_time/posix_time_duration.hpp:57:16: error: no type named ‘type’ in ‘struct boost::enable_if<boost::is_integral<double>, void>’
/usr/include/boost/date_time/posix_time/posix_time_duration.hpp:53:30: note: candidate: ‘boost::posix_time::seconds::seconds(const boost::posix_time::seconds&)’
53 | class BOOST_SYMBOL_VISIBLE seconds : public time_duration
| ^~~~~~~
/usr/include/boost/date_time/posix_time/posix_time_duration.hpp:53:30: note: no known conversion for argument 1 from ‘double’ to ‘const boost::posix_time::seconds&’
/usr/include/boost/date_time/posix_time/posix_time_duration.hpp:53:30: note: candidate: ‘boost::posix_time::seconds::seconds(boost::posix_time::seconds&&)’
/usr/include/boost/date_time/posix_time/posix_time_duration.hpp:53:30: note: no known conversion for argument 1 from ‘double’ to ‘boost::posix_time::seconds&&’
What I can think of is the use of the line boost::posix_time::seconds(60.0) is not correct but I am not able to figure out what's the correct way to instantiate the posix_time::seconds class based on the above definitions. Do any of you have an idea about it?
That constructor takes an integral (whole) number. boost::posix_time::seconds(60) should work.
Reference
This is my tmp.hpp:
#include <cstdlib>
#include <utility>
#include <unordered_map>
using namespace std;
struct int_int_hasher {
size_t operator()(pair<int, int> const& p) const {
return static_cast<size_t>(p.first) << 32 | p.second;
}
};
template<class T, class H>
class BiBag {
unordered_map<T, uint, H> t_to_id_;
};
And simple tmp.cpp:
#include "tmp.hpp"
class tmp {
BiBag<pair<int, int>, int_int_hasher> tt =
BiBag<std::pair<int, int>, int_int_hasher>();
};
The error message is beyond my understanding:
g++ -std=c++11 -O2 tmp.cpp -lm -o tmp
tmp.cpp:6:32: error: expected ‘;’ at end of member declaration
BiBag<std::pair<int, int>, int_int_hasher>();
^
tmp.cpp:6:32: error: declaration of ‘BiBag<std::pair<int, int>, int_int_hasher> tmp::int_int_hasher’ [-fpermissive]
In file included from tmp.cpp:2:0:
tmp.hpp:7:8: error: changes meaning of ‘int_int_hasher’ from ‘struct int_int_hasher’ [-fpermissive]
struct int_int_hasher {
^
tmp.cpp:6:46: error: expected unqualified-id before ‘>’ token
BiBag<std::pair<int, int>, int_int_hasher>();
^
tmp.cpp:6:16: error: wrong number of template arguments (1, should be 2)
BiBag<std::pair<int, int>, int_int_hasher>();
^
If I remove the hasher from the picture and replace the map with a simple <int,int> map I get no error.
Thank you.
I'm new here, so i hope to ask my question in a proper way! :)
I'm trying to implement a solver for the dissipativ lindblad equation with odeint in C++ using the Eigen libary for handling matrices.
With constant steps size everything works fine, but when I try to add an error estimation, the compiler vomits 50 errors.
I suggest I have an error in the typedefs, but I have no idea where.
Here ist the call of the solver:
typedef runge_kutta4<state_type, double, state_type, double,vector_space_algebra > stepper;
typedef runge_kutta_cash_karp54< state_type > error_stepper_type;
typedef controlled_runge_kutta< error_stepper_type > controlled_stepper_type;
controlled_stepper_type controlled_stepper;
integrate_adaptive( controlled_stepper , bath , rho_init , 0.0 , 10.0 , 0.01 );
Here ist the call of the class for the ODE:
void qsys::operator() ( state_type &rho ,
state_type &drhodt , const double t )
{
state_type sum;
sum.resize(rho.rows(),rho.cols());
sum.setZero();
super_op(lindblads,rho,sum);
drhodt=-(H*rho-rho*H) + sum;
}
void qsys::super_op(const std::vector<lindblad_op*> lindblads,const state_type &rho, state_type &erg)
{
state_type a;
state_type b;
a.resize(rho.rows(),rho.cols());
b.resize(rho.rows(),rho.cols());
b.setZero();
erg.setZero();
for (unsigned int i=0;i<lindblads.size();i++){
a.setZero();
a= (lindblads[i]->m) * rho * (lindblads[i]->m.adjoint()) -
0.5 * ((lindblads[i]->m.adjoint()) * (lindblads[i]->m) * rho + rho * (lindblads[i]->m.adjoint() * lindblads[i]->m));
b=erg+a;
erg=b;
}
}
And state_type is Eigen::MatrixXd
Is this helpful for you?
I looked at the error messages, they are 26 pages long, so I wasnt able to post ist here, is there any opportunity to get it online?
I've downloaded boost 1.61 now, but it still doesnt work, my includes:
#ifndef qsys_HPP
#define qsys_HPP
#include <Eigen/Core>
#include <vector>
#include <iostream>
#include <vector>
#include <iostream>
//#include "boost/boost/numeric/odeint/external/eigen/eigen.hpp"
#include "boost/boost/numeric/odeint/algebra/vector_space_algebra.hpp"
#include "boost/boost/numeric/odeint.hpp"
#include "boost/boost/program_options.hpp"
#include <fstream>
#include "lindblad_op.hpp"
With "boost/boost/numeric/odeint/external/eigen/eigen.hpp" I now get following error messages:
||=== Build: Debug in ProgPrak (compiler: GNU GCC Compiler) ===|
/usr/include/boost/numeric/odeint/external/eigen/eigen_algebra.hpp|98|error: ‘vector_space_norm_inf’ is not a class template|
/usr/include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp|28|error: ‘algebra_dispatcher_sfinae’ is not a class template|
/usr/include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp|29|error: ‘enable_if’ in namespace ‘boost’ does not name a type|
/usr/include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp|29|error: expected template-argument before ‘<’ token|
/usr/include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp|29|error: expected ‘>’ before ‘<’ token|
/usr/include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp|37|error: ‘enable_if’ in namespace ‘boost’ does not name a type|
/usr/include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp|37|error: expected template-argument before ‘<’ token|
/usr/include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp|37|error: expected ‘>’ before ‘<’ token|
/usr/include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp|37|error: wrong number of template arguments (2, should be 1)|
/usr/include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp|29|error: provided for ‘template<class Derived> struct boost::numeric::odeint::algebra_dispatcher_sfinae’|
/usr/include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp|38|error: expected ‘::’ before ‘{’ token|
/usr/include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp|38|error: expected identifier before ‘{’ token|
/usr/include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp|38|error: qualified name does not name a class before ‘{’ token|
/usr/include/boost/numeric/odeint/external/eigen/eigen_resize.hpp|38|error: ‘is_resizeable_sfinae’ is not a class template|
/usr/include/boost/numeric/odeint/external/eigen/eigen_resize.hpp|48|error: wrong number of template arguments (2, should be 1)|
/usr/include/boost/numeric/odeint/external/eigen/eigen_resize.hpp|39|error: provided for ‘template<class Derived> struct boost::numeric::odeint::is_resizeable_sfinae’|
/usr/include/boost/numeric/odeint/external/eigen/eigen_resize.hpp|57|error: ‘same_size_impl_sfinae’ is not a class template|
/usr/include/boost/numeric/odeint/external/eigen/eigen_resize.hpp|69|error: wrong number of template arguments (3, should be 1)|
/usr/include/boost/numeric/odeint/external/eigen/eigen_resize.hpp|58|error: provided for ‘template<class Derived> struct boost::numeric::odeint::same_size_impl_sfinae’|
/usr/include/boost/numeric/odeint/external/eigen/eigen_resize.hpp|81|error: ‘resize_impl_sfinae’ is not a class template|
/usr/include/boost/numeric/odeint/external/eigen/eigen_resize.hpp|92|error: wrong number of template arguments (3, should be 1)|
/usr/include/boost/numeric/odeint/external/eigen/eigen_resize.hpp|82|error: provided for ‘template<class Derived> struct boost::numeric::odeint::resize_impl_sfinae’|
/usr/include/boost/numeric/odeint/algebra/algebra_dispatcher.hpp|40|error: redeclared with 2 template parameters|
/usr/include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp|29|note: previous declaration ‘template<class Derived> struct boost::numeric::odeint::algebra_dispatcher_sfinae’ used 1 template parameter|
/usr/include/boost/numeric/odeint/algebra/algebra_dispatcher.hpp|58|error: wrong number of template arguments (2, should be 1)|
/usr/include/boost/numeric/odeint/external/eigen/eigen_algebra_dispatcher.hpp|29|error: provided for ‘template<class Derived> struct boost::numeric::odeint::algebra_dispatcher_sfinae’|
/usr/include/boost/numeric/odeint/util/multi_array_adaption.hpp|70|error: wrong number of template arguments (2, should be 1)|
/usr/include/boost/numeric/odeint/external/eigen/eigen_resize.hpp|39|error: provided for ‘template<class Derived> struct boost::numeric::odeint::is_resizeable_sfinae’|
/usr/include/boost/numeric/odeint/util/multi_array_adaption.hpp|88|error: wrong number of template arguments (3, should be 1)|
/usr/include/boost/numeric/odeint/external/eigen/eigen_resize.hpp|58|error: provided for ‘template<class Derived> struct boost::numeric::odeint::same_size_impl_sfinae’|
/usr/include/boost/numeric/odeint/util/multi_array_adaption.hpp|110|error: wrong number of template arguments (3, should be 1)|
/usr/include/boost/numeric/odeint/external/eigen/eigen_resize.hpp|82|error: provided for ‘template<class Derived> struct boost::numeric::odeint::resize_impl_sfinae’|
If I only include "boost/boost/numeric/odeint/algebra/vector_space_algebra.hpp" I get the following messages:
/usr/include/boost/numeric/odeint/util/multi_array_adaption.hpp|70|error: ‘is_resizeable_sfinae’ is not a class template|
/usr/include/boost/numeric/odeint/util/multi_array_adaption.hpp|81|error: ‘same_size_impl_sfinae’ is not a class template|
/usr/include/boost/numeric/odeint/util/multi_array_adaption.hpp|103|error: ‘resize_impl_sfinae’ is not a class template|
Thanks for your help!
I am having trouble with C++. I want to be able to put an expression inside a template as an argument. Here is my code:
#include <vector>
using namespace std;
vector< ((1>0) ? float : int) > abc() {
}
int main(void){
return 0;
}
This gives me the error:
main.cpp:11:14: error: template argument 1 is invalid
main.cpp:11:14: error: template argument 2 is invalid
main.cpp:11:15: error: expected unqualified-id before ‘{’ token
In the end I want to be able to replace 1 and 0 for whatever and also float and int for typename T and U. Why does it think there are two arguments? And how do I solve this?
(Sorry if this is a duplicate I did have a good look for solutions)
Use std::conditional:
#include <type_traits>
std::vector<std::conditional<(1 > 0), float, int>::type> abc() {}
Starting the the error, which is showed by building the following code:
Testfile.cpp:27:41: error: variable ‘boost::numeric::ublas::matrix_column<boost::numeric::ublas::bounded_matrix<double, 2u, 2u> > op1’ has initialiser but incomplete type.
Please condider the following code:
//! System includes
#include <iostream>
#include <fstream>
//! Boost includes
#include <boost/lexical_cast.hpp>
#include <boost/integer/static_min_max.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/array.hpp>
int main( )
{
namespace ublas = boost::numeric::ublas;
typedef ublas::bounded_matrix<double,2,2> MatDofDdim;
typedef ublas::bounded_vector<double,2> VecDof;
MatDofDdim op;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
op(i,j)=i+j;
}
}
//VecDof op1;
ublas::matrix_column<MatDofDdim> op1 ( op, 1 ) ;
//VecDof op1( ublas::matrix_column<MatDofDdim>( op, 1 ));
return 0;
}
I also tried an different approach with comment the line "ublas::matrix_column<MatDofDdim> op1 ( op, 1 ) ;" and with uncomment the preceeding and following line.
Then it says:
Testfile.cpp:29:48: error: redeclaration of ‘VecDof op1’
Testfile.cpp:26:9: error: ‘VecDof op1’ previously declared here
Testfile.cpp:29:54: error: invalid use of incomplete type ‘struct boost::numeric::ublas::matrix_column<boost::numeric::ublas::bounded_matrix<double, 2u, 2u> >’
/usr/include/boost/numeric/ublas/fwd.hpp:75:11: error: declaration of ‘struct boost::numeric::ublas::matrix_column<boost::numeric::ublas::bounded_matrix<double, 2u, 2u> >’
I use eclipse in ubuntu with g++.
matrix_column is declared in <boost/numeric/ublas/matrix_proxy.hpp>
http://www.boost.org/doc/libs/1_51_0/libs/numeric/ublas/doc/matrix_proxy.htm#matrix_column