当我使用icc编译器在Fedora 26 linux系统中编译一个简单的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版本17.0.0(gcc版本7.0.0兼容性),
gcc版本是gcc版本7.1.1 20170622(Red Hat 7.1.1-3)(GCC),
对于这个错误,我感到困惑。请帮我。谢谢!
答案 0 :(得分:2)
__builtin_addressof
是一个相对较新的gcc内置icpc,不知道如何处理。它于2016年10月左右被添加到gcc,而icc 17.0于2016年4月发布。
要么降级你的gcc,要么通过#define
__builtin_addressof
解决问题,如下所示:
#define __builtin_addressof(obj) \
(&const_cast<char&>(reinterpret_cast<const volatile char&>(obj)))
用icpc编译时。您可以将define添加到源代码的顶部,或者将相应的-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,但至少你应该能够编译一些星星是正确的。
答案 1 :(得分:1)
编译器通常有自己的库代码(.h / lib等)来实现标准库功能。这些库大多与其他编译器不兼容(例如,编译器A将无法构建编译器B的库代码)。
当然,您编写的代码将由两个编译器编译。
看起来您遇到的错误与此问题有关:
/usr/include/c++/7/bits/move.h(48)
这些是标准的gcc库包含文件。您需要更改环境/ seartch路径,以使用icpc include / lib文件夹。
__ builtin_addressof是gcc在内部支持的'内在',但不是C ++标准的一部分(你可以在函数之前通过__来表示,这通常意味着'编译器特定的功能')。