gpt4 book ai didi

c++ - 英特尔 icc : compile c++ code cause error

转载 作者:行者123 更新时间:2023-11-27 22:41:29 25 4
gpt4 key购买 nike

当我在Fedora 26 linux系统中使用icc编译器编译一个简单的c++代码时,出现如下错误:

icc命令:

icpc test.cpp

test.cpp内容:

#include<iostream>
using namespace std;
int main() {
cout<<"hello world" << endl;
return 0;
}

它导致了如下错误:

/usr/include/c++/7/bits/move.h(48): error: identifier "__builtin_addressof" is undefined
{ return __builtin_addressof(__r); }
^
detected during:
instantiation of "_Tp *std::__addressof(_Tp &) [with _Tp=std::__make_not_void<char>={char}]" at line 138
instantiation of "_Tp *std::addressof(_Tp &) [with _Tp=std::__make_not_void<char>={char}]" at line 142 of "/usr/include/c++/7/bits/ptr_traits.h"
instantiation of "std::pointer_traits<_Tp *>::pointer std::pointer_traits<_Tp *>::pointer_to(std::__make_not_void<std::pointer_traits<_Tp *>::element_type> &) [with _Tp=char]" at line 166 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::pointer std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_local_data() [with _CharT=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]" at line 485 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT *, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc &) [with _CharT=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]" at line 6473 of "/usr/include/c++/7/bits/basic_string.h"

/usr/include/c++/7/bits/move.h(48): error: identifier "__builtin_addressof" is undefined
{ return __builtin_addressof(__r); }
^
detected during:
instantiation of "_Tp *std::__addressof(_Tp &) [with _Tp=std::__make_not_void<const char>={const char}]" at line 138
instantiation of "_Tp *std::addressof(_Tp &) [with _Tp=std::__make_not_void<const char>={const char}]" at line 142 of "/usr/include/c++/7/bits/ptr_traits.h"
instantiation of "std::pointer_traits<_Tp *>::pointer std::pointer_traits<_Tp *>::pointer_to(std::__make_not_void<std::pointer_traits<_Tp *>::element_type> &) [with _Tp=const char]" at line 176 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::const_pointer std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_local_data() const [with _CharT=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]" at line 195 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "bool std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_is_local() const [with _CharT=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]" at line 204 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_dispose() [with _CharT=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]" at line 228 of "/usr/include/c++/7/bits/basic_string.tcc"
instantiation of "void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct(_FwdIterator, _FwdIterator, std::forward_iterator_tag) [with _CharT=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>, _FwdIterator=const char *]" at line 220 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct_aux(_InIterator, _InIterator, std::__false_type) [with _CharT=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>, _InIterator=const char *]" at line 239 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct(_InIterator, _InIterator) [with _CharT=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>, _InIterator=const char *]" at line 486 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT *, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc &) [with _CharT=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]" at line 6473 of "/usr/include/c++/7/bits/basic_string.h"

/usr/include/c++/7/bits/move.h(48): error: identifier "__builtin_addressof" is undefined
{ return __builtin_addressof(__r); }
^
detected during:
instantiation of "_Tp *std::__addressof(_Tp &) [with _Tp=std::__make_not_void<wchar_t>={wchar_t}]" at line 138
instantiation of "_Tp *std::addressof(_Tp &) [with _Tp=std::__make_not_void<wchar_t>={wchar_t}]" at line 142 of "/usr/include/c++/7/bits/ptr_traits.h"
instantiation of "std::pointer_traits<_Tp *>::pointer std::pointer_traits<_Tp *>::pointer_to(std::__make_not_void<std::pointer_traits<_Tp *>::element_type> &) [with _Tp=wchar_t]" at line 166 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::pointer std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_local_data() [with _CharT=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>]" at line 485 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT *, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc &) [with _CharT=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>]" at line 6479 of "/usr/include/c++/7/bits/basic_string.h"

/usr/include/c++/7/bits/move.h(48): error: identifier "__builtin_addressof" is undefined
{ return __builtin_addressof(__r); }
^
detected during:
instantiation of "_Tp *std::__addressof(_Tp &) [with _Tp=std::__make_not_void<const wchar_t>={const wchar_t}]" at line 138
instantiation of "_Tp *std::addressof(_Tp &) [with _Tp=std::__make_not_void<const wchar_t>={const wchar_t}]" at line 142 of "/usr/include/c++/7/bits/ptr_traits.h"
instantiation of "std::pointer_traits<_Tp *>::pointer std::pointer_traits<_Tp *>::pointer_to(std::__make_not_void<std::pointer_traits<_Tp *>::element_type> &) [with _Tp=const wchar_t]" at line 176 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::const_pointer std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_local_data() const [with _CharT=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>]" at line 195 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "bool std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_is_local() const [with _CharT=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>]" at line 204 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_dispose() [with _CharT=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>]" at line 228 of "/usr/include/c++/7/bits/basic_string.tcc"
instantiation of "void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct(_FwdIterator, _FwdIterator, std::forward_iterator_tag) [with _CharT=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>, _FwdIterator=const wchar_t *]" at line 220 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct_aux(_InIterator, _InIterator, std::__false_type) [with _CharT=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>, _InIterator=const wchar_t *]" at line 239 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct(_InIterator, _InIterator) [with _CharT=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>, _InIterator=const wchar_t *]" at line 486 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT *, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc &) [with _CharT=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>]" at line 6479 of "/usr/include/c++/7/bits/basic_string.h"

/usr/include/c++/7/bits/move.h(48): error: identifier "__builtin_addressof" is undefined
{ return __builtin_addressof(__r); }
^
detected during:
instantiation of "_Tp *std::__addressof(_Tp &) [with _Tp=std::__make_not_void<char16_t>={char16_t}]" at line 138
instantiation of "_Tp *std::addressof(_Tp &) [with _Tp=std::__make_not_void<char16_t>={char16_t}]" at line 142 of "/usr/include/c++/7/bits/ptr_traits.h"
instantiation of "std::pointer_traits<_Tp *>::pointer std::pointer_traits<_Tp *>::pointer_to(std::__make_not_void<std::pointer_traits<_Tp *>::element_type> &) [with _Tp=char16_t]" at line 166 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::pointer std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_local_data() [with _CharT=char16_t, _Traits=std::char_traits<char16_t>, _Alloc=std::allocator<char16_t>]" at line 485 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT *, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc &) [with _CharT=char16_t, _Traits=std::char_traits<char16_t>, _Alloc=std::allocator<char16_t>]" at line 6486 of "/usr/include/c++/7/bits/basic_string.h"

/usr/include/c++/7/bits/move.h(48): error: identifier "__builtin_addressof" is undefined
{ return __builtin_addressof(__r); }
^
detected during:
instantiation of "_Tp *std::__addressof(_Tp &) [with _Tp=std::__make_not_void<const char16_t>={const char16_t}]" at line 138
instantiation of "_Tp *std::addressof(_Tp &) [with _Tp=std::__make_not_void<const char16_t>={const char16_t}]" at line 142 of "/usr/include/c++/7/bits/ptr_traits.h"
instantiation of "std::pointer_traits<_Tp *>::pointer std::pointer_traits<_Tp *>::pointer_to(std::__make_not_void<std::pointer_traits<_Tp *>::element_type> &) [with _Tp=const char16_t]" at line 176 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::const_pointer std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_local_data() const [with _CharT=char16_t, _Traits=std::char_traits<char16_t>, _Alloc=std::allocator<char16_t>]" at line 195 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "bool std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_is_local() const [with _CharT=char16_t, _Traits=std::char_traits<char16_t>, _Alloc=std::allocator<char16_t>]" at line 204 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_dispose() [with _CharT=char16_t, _Traits=std::char_traits<char16_t>, _Alloc=std::allocator<char16_t>]" at line 228 of "/usr/include/c++/7/bits/basic_string.tcc"
instantiation of "void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct(_FwdIterator, _FwdIterator, std::forward_iterator_tag) [with _CharT=char16_t, _Traits=std::char_traits<char16_t>, _Alloc=std::allocator<char16_t>, _FwdIterator=const char16_t *]" at line 220 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct_aux(_InIterator, _InIterator, std::__false_type) [with _CharT=char16_t, _Traits=std::char_traits<char16_t>, _Alloc=std::allocator<char16_t>, _InIterator=const char16_t *]" at line 239 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct(_InIterator, _InIterator) [with _CharT=char16_t, _Traits=std::char_traits<char16_t>, _Alloc=std::allocator<char16_t>, _InIterator=const char16_t *]" at line 486 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT *, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc &) [with _CharT=char16_t, _Traits=std::char_traits<char16_t>, _Alloc=std::allocator<char16_t>]" at line 6486 of "/usr/include/c++/7/bits/basic_string.h"

/usr/include/c++/7/bits/move.h(48): error: identifier "__builtin_addressof" is undefined
{ return __builtin_addressof(__r); }
^
detected during:
instantiation of "_Tp *std::__addressof(_Tp &) [with _Tp=std::__make_not_void<char32_t>={char32_t}]" at line 138
instantiation of "_Tp *std::addressof(_Tp &) [with _Tp=std::__make_not_void<char32_t>={char32_t}]" at line 142 of "/usr/include/c++/7/bits/ptr_traits.h"
instantiation of "std::pointer_traits<_Tp *>::pointer std::pointer_traits<_Tp *>::pointer_to(std::__make_not_void<std::pointer_traits<_Tp *>::element_type> &) [with _Tp=char32_t]" at line 166 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::pointer std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_local_data() [with _CharT=char32_t, _Traits=std::char_traits<char32_t>, _Alloc=std::allocator<char32_t>]" at line 485 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT *, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc &) [with _CharT=char32_t, _Traits=std::char_traits<char32_t>, _Alloc=std::allocator<char32_t>]" at line 6491 of "/usr/include/c++/7/bits/basic_string.h"

/usr/include/c++/7/bits/move.h(48): error: identifier "__builtin_addressof" is undefined
{ return __builtin_addressof(__r); }
^
detected during:
instantiation of "_Tp *std::__addressof(_Tp &) [with _Tp=std::__make_not_void<const char32_t>={const char32_t}]" at line 138
instantiation of "_Tp *std::addressof(_Tp &) [with _Tp=std::__make_not_void<const char32_t>={const char32_t}]" at line 142 of "/usr/include/c++/7/bits/ptr_traits.h"
instantiation of "std::pointer_traits<_Tp *>::pointer std::pointer_traits<_Tp *>::pointer_to(std::__make_not_void<std::pointer_traits<_Tp *>::element_type> &) [with _Tp=const char32_t]" at line 176 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::const_pointer std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_local_data() const [with _CharT=char32_t, _Traits=std::char_traits<char32_t>, _Alloc=std::allocator<char32_t>]" at line 195 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "bool std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_is_local() const [with _CharT=char32_t, _Traits=std::char_traits<char32_t>, _Alloc=std::allocator<char32_t>]" at line 204 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_dispose() [with _CharT=char32_t, _Traits=std::char_traits<char32_t>, _Alloc=std::allocator<char32_t>]" at line 228 of "/usr/include/c++/7/bits/basic_string.tcc"
instantiation of "void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct(_FwdIterator, _FwdIterator, std::forward_iterator_tag) [with _CharT=char32_t, _Traits=std::char_traits<char32_t>, _Alloc=std::allocator<char32_t>, _FwdIterator=const char32_t *]" at line 220 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct_aux(_InIterator, _InIterator, std::__false_type) [with _CharT=char32_t, _Traits=std::char_traits<char32_t>, _Alloc=std::allocator<char32_t>, _InIterator=const char32_t *]" at line 239 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_construct(_InIterator, _InIterator) [with _CharT=char32_t, _Traits=std::char_traits<char32_t>, _Alloc=std::allocator<char32_t>, _InIterator=const char32_t *]" at line 486 of "/usr/include/c++/7/bits/basic_string.h"
instantiation of "std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT *, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type, const _Alloc &) [with _CharT=char32_t, _Traits=std::char_traits<char32_t>, _Alloc=std::allocator<char32_t>]" at line 6491 of "/usr/include/c++/7/bits/basic_string.h"

compilation aborted for test.cpp (code 2)

我的icc版本是icc version 17.0.0 (gcc version 7.0.0 compatible),

gcc版本为gcc version 7.1.1 20170622 (Red Hat 7.1.1-3) (GCC),

对于这个错误,我感到很困惑。请帮我。谢谢!

最佳答案

__builtin_addressof 是一个比较新的gcc built-in icpc 还不知道怎么处理。它于 2016 年 10 月左右添加到 gcc 中,而 icc 17.0 于 2016 年 4 月发布。

要么降级你的 gcc,要么通过 #defineing __builtin_addressof 解决这个问题,如下所示:

#define __builtin_addressof(obj) \
(&const_cast<char&>(reinterpret_cast<const volatile char&>(obj)))

使用 icpc 编译时。您可以将定义添加到源代码的顶部,或者将相应的 -D 标志添加到编译器命令行,或者(如果您喜欢冒险)修补系统头文件:

   template<typename _Tp>
inline _GLIBCXX_CONSTEXPR _Tp*
__addressof(_Tp& __r) _GLIBCXX_NOEXCEPT
#ifdef __ICC
{ return (&const_cast<char&>(reinterpret_cast<const volatile char&>(__r))); }
#else
{ return __builtin_addressof(__r); }
#endif

这不符合 C++17,但至少如果星星是正确的,你应该能够编译一些东西。

关于c++ - 英特尔 icc : compile c++ code cause error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48639190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com