'why the first example in xtensor can't run?
I install the xtensor by conda
conda install -c conda-forge xtensor
and I find the position where the xtensor is installed,
path_xtensor="/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/"
path_xtl="/amax/home/user/miniconda3/pkgs/xtl-0.7.2-h4bd325d_1/include/"
the first example is given by the xtensor docs, i.e.
#include <iostream>
#include <xtensor/xarray.hpp>
#include <xtensor/xio.hpp>
#include <xtensor/xview.hpp>
int main(int argc, char* argv[])
{
xt::xarray<double> arr1
{{1.0, 2.0, 3.0},
{2.0, 5.0, 7.0},
{2.0, 5.0, 7.0}};
xt::xarray<double> arr2
{5.0, 6.0, 7.0};
xt::xarray<double> res = xt::view(arr1, 1) + arr2;
std::cout << res << std::endl;
return 0;
}
I followed that and run the command in linux servers
g++ -I path_xtensor -I path_xtl x.cpp -o x
but the command cause error, the log is too long, the following is partly:
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:931:63: error: ‘int xt::xfunction_iterator<F, CT>::deref_impl’ is not a static data member of ‘class xt::xfunction_iterator<F, CT>’
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:931:63: error: template definition of non-template ‘int xt::xfunction_iterator<F, CT>::deref_impl’
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:931:58: error: ‘index_sequence’ is not a member of ‘std’
inline auto xfunction_iterator<F, CT...>::deref_impl(std::index_sequence<I...>) const -> reference
^
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:936:29: warning: variadic templates only available with -std=c++11 or -std=gnu++11
template <class F, class... CT>
^
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:937:30: warning: variadic templates only available with -std=c++11 or -std=gnu++11
template <std::size_t... I>
^
...
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp: In member function ‘void xt::xfunction_stepper<F, CT>::step_leading()’:
/amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xfunction.hpp:1058:14: error: ‘ame a type
virtual const char what() const noexcept override { return "bad_variant_access"; }
^
/amax/home/user/miniconda3/pkgs/xtl-0.7.2-h4bd325d_1/include/xtl/xvariant_impl.hpp:914:38: note: C++11 ‘noexcept’ only available with -std=c++11 or -std=gnu++11
/amax/home/user/miniconda3/pkgs/xtl-0.7.2-h4bd325d_1/include/xtl/xvariant_impl.hpp:914:25: error: looser throw specifier for ‘virtual const char mpark::bad_variant_access::what() const’
virtual const char what() const noexcept override { return "bad_variant_access"; }
^
In file included from /usr/include/c++/5/ios:39:0,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from x.cpp:24:
/usr/include/c++/5/exception:68:25: error: overriding ‘virtual const char std::exception::what() const throw ()’
virtual const char* what() const _GLIBCXX_USE_NOEXCEPT;
^
In file included from /amax/home/user/miniconda3/pkgs/xtl-0.7.2-h4bd325d_1/include/xtl/xvariant.hpp:13:0,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xstrided_view.hpp:20,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xgenerator.hpp:27,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xbuilder.hpp:31,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xmanipulation.hpp:13,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xmath.hpp:28,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xcontainer.hpp:25,
from /amax/home/user/miniconda3/pkgs/xtensor-0.23.10-h4bd325d_0/include/xtensor/xarray.hpp:20,
from x.cpp:25:
/amax/home/user/miniconda3/pkgs/xtl-0.7.2-h4bd325d_1/include/xtl/xvariant_impl.hpp:917:3: error: expected unqualified-id before ‘[’ token
[[noreturn]] inline void throw_bad_variant_access() {
^
x.cpp:38:1: error: expected ‘}’ at end of input
}
Thanks in advance for any help/suggestion.
Solution 1:[1]
Is the following command the full command line you execute?
g++ -I path_xtensor -I path_xtl x.cpp -o x
Then it is missing two helpful options:
- To ensure the compiler is using a modern c++ standard, add an option like
-std=c++11
or-std=c++14
or even newer standards, depending what your compiler supports and what you want to use in the remainder of your project. xtensor requires at leastc++11
. - To ensure that the compiler will use good CPU optimizations for the binary, add flags that enable general performance optimizations like
-O2
and specific hardware optimizations for your current CPU like-march=native
, unless you want your resulting binary to be portable to other computers (with a less modern CPU). This can give an huge performance boost with xtensor.
Does that help?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | emmenlau |