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.
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 least c++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?
Related
gcc5.4 doesn't compile the following code:
// source.cpp
int nonconstexprfunc()
{
return 14;
}
constexpr int func(int n)
{
if (n < 0)
return nonconstexprfunc();
return n*n;
}
int main()
{
constexpr int t1 = func(0);
return 0;
}
The command I use:
$ g++ -std=c++14 -c source.cpp
The output:
In function ‘constexpr int func(int)’:
error: ‘constexpr int func(int)’ called in a constant expression
constexpr int t1 = func(0);
In function ‘int main()’:
error: ‘constexpr int func(int)’ called in a constant expression
constexpr int t1 = func(0);
But I can compile that source.cpp using gcc6.4. Doesn't gcc5.4 fully support constexpr functions?
More interestingly I can compile that source.cpp using icpc (Intel C++ compiler) that uses gcc5.4 - I suppose there must be an option to compile that code using gcc5.4.
$ icpc -v
icpc version 19.0 (gcc version 5.4.0 compatibility)
$ icpc -std=c++14 -c source.cpp
no errors
The first limitation is concerning the use gcc 5.4 with -std=c++11 which produces the error because of the two return statement see The body of constexpr function not a return-statement so in order to lift your first issue you need to use -std=c++14
It then produces
'#1 with x86-64 gcc 5.4
: In function 'constexpr int func(int)':
:10:32: error: call to non-constexpr function 'int
nonconstexprfunc()'
return nonconstexprfunc(); ^
: In function 'int main()':
:16:28: error: 'constexpr int func(int)' called in a constant
expression
constexpr int t1 = func(0);
Compiler returned: 1
This next error produced seems to be a known GCC bug (misinterpretation of c++14) see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86678
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67026
You can also check out calling non constexpr function from constexpr allowed in some conditions
However judging from the error it produces:
It seems pretty obvious that doing
constexpr int nonconstexprfunc()
{
return 14;
}
will solve the error and will be more efficient in your case.
Check the difference with https://www.godbolt.org/ of adding constexpr or not using gcc 8.2 for example.
I get an error when compile code containing <experimental/any>.
Code in main.cpp:
#include <experimental/any>
int main() { }
Compile this (clang version is 3.9):
clang++ main.cpp -o main -std=c++1z
Error after the compiling:
In file included from main.cpp:2:
/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/experimental/any:364:34: error:
no template named '__any_caster'; did you mean 'any_cast'?
return static_cast<_ValueType*>(__any_caster<_ValueType>(__any));
^
/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/experimental/any:361:30: note:
'any_cast' declared here
inline const _ValueType* any_cast(const any* __any) noexcept
^
/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/experimental/any:372:34: error:
no template named '__any_caster'; did you mean 'any_cast'?
return static_cast<_ValueType*>(__any_caster<_ValueType>(__any));
^
/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/experimental/any:369:24: note:
'any_cast' declared here
inline _ValueType* any_cast(any* __any) noexcept
^
2 errors generated.
As #chris mentioned in the comments:
You could try with libc++. Perhaps there's an incompatibility with Clang in libstdc++'s new header.
This turns out to be true. Clang 3.9 is still experimental, and so it uses experimental headers, including a experimental C++ standard library. By default, it is provided by GCC, and so an incompatibility occurs between the GCC implementation and the Clang implementation.
I try to compile the simple code
#include <atomic>
int bar = 0;
void foo(std::atomic<int>&flag)
{ bar = flag; }
with clang++ 3.2 (downloaded as llvm 3.2 from llvm.org; on mac os.x 10.8.3 this fails with the error
/> clang++ -std=c++11 -stdlib=libc++ -O3 -march=native -c test.cc
In file included from test.cc:1:
/usr/include/c++/v1/atomic:576:17: error: first argument to atomic operation must be a pointer to non-const _Atomic type ('const _Atomic(int) *' invalid)
{return __c11_atomic_load(&__a_, __m);}
^ ~~~~~
/usr/include/c++/v1/atomic:580:53: note: in instantiation of member function
'std::_1::_atomic_base::load' requested here
operator _Tp() const _NOEXCEPT {return load();}
^
test.cc:5:9: note: in instantiation of member function 'std::_1::_atomic_base::operator int' requested here
bar = done;
When I use /usr/bin/clang++ instead (which comes with the OS or Xcode) it compiles just fine. The libc++ is that at /usr/lib/c++/v1 in both cases.
What am I missing? Is there another libc++ that comes with llvm 3.2 but which I'm missing? (I cannot find anything in the clang3.2 tree).
Xcode now bundles libc++ within the Xcode.app directory. You can inspect this directory by control-clicking Xcode.app and choose "Show Package Contents".
MinGw 4.7.0 Boost 1.47
code:
#include <iostream>
#include <boost/thread.hpp>
int main(int argc, char *argv[])
{
std::cout<<"In main"<<std::endl;
}
Compiler string:
g++.exe -Wall -fexceptions -g -IC:\soft\ides_comp\mingw\include\boost_1_47_0 -c D:\work\cpp_cb\mt1\main.cpp -o obj\Debug\main.o
It doesnt compile and i have same error whatever compiler options i tried.
Warning:
In file included from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/win32/thread_data.hpp:12:0,
from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/thread.hpp:15,
from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread.hpp:13,
from D:\work\cpp_cb\mt1\main.cpp:2:
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/win32/thread_heap_alloc.hpp:59:40: warning: inline function 'void* boost::detail::allocate_raw_heap_memory(unsigned int)' declared as dllimport: attribute ignored [-Wattributes]
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/win32/thread_heap_alloc.hpp:69:39: warning: inline function 'void boost::detail::free_raw_heap_memory(void*)' declared as dllimport: attribute ignored [-Wattributes]
Error:
In file included from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/smart_ptr/shared_ptr.hpp:30:0,
from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/shared_ptr.hpp:17,
from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/date_time/time_clock.hpp:17,
from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/thread_time.hpp:9,
from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/win32/thread_data.hpp:10,
from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread/thread.hpp:15,
from C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/thread.hpp:13,
from D:\work\cpp_cb\mt1\main.cpp:2:
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/checked_delete.hpp: In instantiation of 'void boost::checked_delete(T*) [with T = boost::error_info<boost::tag_original_exception_type, const std::type_info*>]':
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/smart_ptr/detail/shared_count.hpp:95:13: required from 'boost::detail::shared_count::shared_count(Y*) [with Y = boost::error_info<boost::tag_original_exception_type, const std::type_info*>]'
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/smart_ptr/shared_ptr.hpp:183:50: required from 'boost::shared_ptr<T>::shared_ptr(Y*) [with Y = boost::error_info<boost::tag_original_exception_type, const std::type_info*>; T = boost::error_info<boost::tag_original_exception_type, const std::type_info*>]'
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/exception/info.hpp:171:69: required from 'const E& boost::exception_detail::set_info(const E&, const boost::error_info<Tag, T>&) [with E = boost::unknown_exception; Tag = boost::tag_original_exception_type; T = const std::type_info*]'
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/exception/info.hpp:192:46: required from 'typename boost::enable_if<boost::exception_detail::derives_boost_exception<E>, const E&>::type boost::operator<<(const E&, const boost::error_info<Tag, T>&) [with E = boost::unknown_exception; Tag = boost::tag_original_exception_type; T = const std::type_info*; typename boost::enable_if<boost::exception_detail::derives_boost_exception<E>, const E&>::type = const boost::unknown_exception&]'
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/exception/detail/exception_ptr.hpp:182:13: required from 'void boost::unknown_exception::add_original_type(const E&) [with E = std::exception]'
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/exception/detail/exception_ptr.hpp:161:32: required from here
Warning 2:
C:\soft\ides_comp\mingw\include\boost_1_47_0/boost/checked_delete.hpp:34:5: warning: deleting object of polymorphic class type 'boost::error_info<boost::tag_original_exception_type, const std::type_info*>' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
What can it be? Thanks
This has been fixed in later boost versions. Check here:
https://svn.boost.org/trac/boost/ticket/6165
Update boost/config/stdlib/libstdcpp3.hpp:
#if defined(_GLIBCXX_HAVE_GTHR_DEFAULT) \
|| defined(_GLIBCXX_HAS_GTHREADS) \
|| defined(_GLIBCXX__PTHREADS) \
|| defined(WIN32)
Added _GLIBCXX_HAS_GTHREADS and/or WIN32 (from the link above, see patch).
WIN32 seems a bit brute force, but doesn't work without (at least not for me. I am using an older boost version 1.42).
If you compiled the thread library for using Win32 threads, you might need
-DBOOST_USE_WINDOWS_H
in your compiler flags. While I don't think that's the issue (I get a different set of errors for not using it), you might give it a try.
This answer maybe not very straight, but:
I do use g++ 4.7.0 20111209 and it has support for threads.
#include <iostream>
#include <thread>
using namespace std;
void foo()
{
cout << "Hello from thread\n";
}
int main()
{
thread th1(foo);
th1.join();
return 0;
}
During compilation use -std=c++11 option to use the latest standard which supports threads
PS:
boost 1.48 compiled on my pc with mingw 4.7.0 gives an error (when trying to use boost::thread):
Threading support unavailable: it has been explicitly disabled with BOOST_DISABLE_THREADS
So I guess it was disabled by default with g++ 4.7.0 (with g++ 4.6.2 it was not).
While building an existing code base on Mac OS using its native build setup I am getting some basic strange error while compilation phase.
Does any of you have any idea, as I have seen it's been discussed earlier as well in this forum without any good reason. I can not see any conflicting files being included.
But still I am unable to compile the code because this error appears.
Source are like the code given below and compilation error appears
$ cat a.h
#include <string>
#include <sstream>
namespace brijesh {
typedef std::string String;
template<class T>
String toString(T value) {
std::ostringstream buffer;
buffer << value;
return buffer.str();
}
$ cat b.h
#include "a.h"
namespace brijesh {
class Platform {
public:
static String getName();
};
}
$ cat b.cpp
#include "b.h"
namespace brijesh {
String Platform::getName()
{
String name = "UNKNOWN";
#ifdef LINUX
name = "linux";
#endif
#ifdef MACOSX
name = "Mac";
#endif
return name;
}
}
flags used for compilation
g++ -c -o test.o -DRELEASE_VERSION -ggdb -arch ppc -mmacosx-version-min=10.4 -pipe -fpermiss ive -nostdinc -nostdinc++ -isystem /Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3 .3 -I/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++ -I/Developer/SDKs/MacOS X10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/ppc-darwin -isystem /Developer/SDKs/MacOSX10.3.9. sdk/usr/include -F/Developer/SDKs/MacOSX10.3.9.sdk/System/Library/Frameworks -Wreturn-type -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -Wall -Wno-multichar -Wno-unk nown-pragmas -Wno-long-double -fconstant-cfstrings -MP -MMD x.cpp
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/bits/locale_facets.h: In constructor 'std::collate_byname<_CharT>::collate_byname(const char*, size_t)':
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/bits/locale_facets.h:1072: error: '_M_c_locale_collate' was not declared in this scope
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/ppc-darwin/bits/messages_members.h: In constructor 'std::messages_byname<_CharT>::messages_byname(const char*, size_t)':
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/ppc-darwin/bits/messages_members.h:79: error: '_M_c_locale_messages' was not declared in this scope
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits: At global scope:
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:897: error: 'float __builtin_huge_valf()' cannot appear in a constant-expression
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:897: error: a function call cannot appear in a constant-expression
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:897: error: 'float __builtin_huge_valf()' cannot appear in a constant-expression
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:897: error: a function call cannot appear in a constant-expression
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:899: error: 'float __builtin_nanf(const char*)' cannot appear in a constant-expression
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:899: error: a function call cannot appear in a constant-expression
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:899: error: 'float __builtin_nanf(const char*)' cannot appear in a constant-expression
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:899: error: a function call cannot appear in a constant-expression
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:900: error: field initializer is not constant
/Developer/SDKs/MacOSX10.3.9.sdk/usr/include/gcc/darwin/3.3/c++/limits:915: error: field initializer is not constant
It looks like you're trying to use OS X 10.3 developer tools (Xcode et al) and are trying to target OS X 10.4, which is obviously not going to work. Either change your build command to remove incompatible flags, such as -mmacosx-version-min=10.4, or upgrade to a more current version of OS X + Xcode + SDKs.