Intel ICC: компиляция кода C++ причина ошибки
Когда я использую компилятор icc для компиляции простого кода на языке C++ в системе Linux Fedora 26, это приводило к ошибке, как показано ниже:
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),
из-за этой ошибки я чувствую смущение. Пожалуйста, помогите мне. Спасибо!
2 ответа
__builtin_addressof
является относительно новым gcc, встроенным в icpc, пока не знает, как с ним обращаться. Он был добавлен в gcc примерно в октябре 2016 года, а icc 17.0 был выпущен в апреле 2016 года.
Либо понизьте ваш gcc, либо обойдите проблему, #define
ИНГ __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, но по крайней мере вы должны быть в состоянии что-то скомпилировать, если звезды правильные.
Обычно компиляторы имеют свой собственный библиотечный код (.h/lib и т. Д.), Который реализует стандартную функциональность библиотеки. Эти библиотеки в основном несовместимы с другими компиляторами (например, компилятор A не сможет создать код библиотеки компилятора B).
Конечно, код, который вы пишете, будет компилироваться обоими компиляторами.
Похоже, ошибки, которые вы получаете, связаны с этой проблемой:
/usr/include/c++/7/bits/move.h(48)
Это стандартные включаемые файлы библиотеки gcc. Вам нужно изменить пути к окружению / seartch, чтобы использовать папки icpc include / lib.
__builtin_addressof является "встроенным", который поддерживается gcc внутренне, но не является частью стандарта C++ (вы можете сказать с помощью __ перед функцией, что обычно означает "специфическую для компилятора функциональность").