std :: size_t вызывает «ошибку: ожидаемый идентификатор перед« без знака »» в заголовке libstdc ++ char_traits.h - PullRequest
0 голосов
/ 27 июня 2018

Я пытаюсь собрать библиотеку netcdf-cxx4 и сталкиваюсь со странной ошибкой, которая появляется в char_traits.h, заголовке libstdc ++. Первая ошибка ниже:

>> $ x86_64-w64-mingw32.static-g++ -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT ncCheck.lo -MD -MP -MF .deps/ncCheck.Tpo -c ncCheck.cpp -o ncCheck.o
In file included from ncCheck.cpp:2:0:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h:104:66: error: expected identifier before 'unsigned'
       compare(const char_type* __s1, const char_type* __s2, std::size_t __n);

Полная ошибка:

$ x86_64-w64-mingw32.static-g++ -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT ncCheck.lo -MD -MP -MF .deps/ncCheck.Tpo -c ncCheck.cpp -o ncCheck.o
In file included from ncCheck.cpp:2:0:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h:104:66: error: expected identifier before 'unsigned'
       compare(const char_type* __s1, const char_type* __s2, std::size_t __n);
                                                                  ^
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h:106:19: error: expected unqualified-id before 'unsigned'
       static std::size_t
                   ^
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h:110:39: error: expected identifier before 'unsigned'
       find(const char_type* __s, std::size_t __n, const char_type& __a);
                                       ^
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h:113:57: error: expected identifier before 'unsigned'
       move(char_type* __s1, const char_type* __s2, std::size_t __n);
                                                         ^
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h:116:57: error: expected identifier before 'unsigned'
       copy(char_type* __s1, const char_type* __s2, std::size_t __n);
                                                         ^
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h:119:35: error: expected identifier before 'unsigned'
       assign(char_type* __s, std::size_t __n, char_type __a);
                                   ^
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h:145:64: error: expected identifier before 'unsigned'
     compare(const char_type* __s1, const char_type* __s2, std::size_t __n)
                                                                ^
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h: In static member function 'static int __gnu_cxx::char_traits<_CharT>::compare(const char_type*, const char_type*, long long unsigned int)':
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h:147:17: error: expected unqualified-id before 'unsigned'
       for (std::size_t __i = 0; __i < __n; ++__i)
                 ^
In file included from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/string:40:0,
                 from ./ncException.h:2,
                 from ncCheck.cpp:3:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h:147:33: error: '__i' was not declared in this scope
       for (std::size_t __i = 0; __i < __n; ++__i)
                                 ^
In file included from ncCheck.cpp:2:0:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h: At global scope:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h:156:10: error: expected unqualified-id before 'unsigned'
     std::size_t
          ^
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h:169:37: error: expected identifier before 'unsigned'
     find(const char_type* __s, std::size_t __n, const char_type& __a)
                                     ^
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h: In static member function 'static const char_type* __gnu_cxx::char_traits<_CharT>::find(const char_type*, long long unsigned int, const char_type&)':
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h:171:17: error: expected unqualified-id before 'unsigned'
       for (std::size_t __i = 0; __i < __n; ++__i)
                 ^
In file included from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/string:40:0,
                 from ./ncException.h:2,
                 from ncCheck.cpp:3:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h:171:33: error: '__i' was not declared in this scope
       for (std::size_t __i = 0; __i < __n; ++__i)
                                 ^
In file included from ncCheck.cpp:2:0:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h: At global scope:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h:180:55: error: expected identifier before 'unsigned'
     move(char_type* __s1, const char_type* __s2, std::size_t __n)
                                                       ^
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h:189:55: error: expected identifier before 'unsigned'
     copy(char_type* __s1, const char_type* __s2, std::size_t __n)
                                                       ^
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/char_traits.h:199:33: error: expected identifier before 'unsigned'
     assign(char_type* __s, std::size_t __n, char_type __a)
                                 ^
In file included from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/ext/new_allocator.h:33:0,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/x86_64-w64-mingw32.static/bits/c++allocator.h:33,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/allocator.h:46,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/string:41,
                 from ./ncException.h:2,
                 from ncCheck.cpp:3:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/new:111:31: error: declaration of 'operator new' as non-function
 void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
                               ^
In file included from ncCheck.cpp:2:0:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/new:111:25: error: expected unqualified-id before 'unsigned'
 void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
                         ^
In file included from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/ext/new_allocator.h:33:0,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/x86_64-w64-mingw32.static/bits/c++allocator.h:33,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/allocator.h:46,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/string:41,
                 from ./ncException.h:2,
                 from ncCheck.cpp:3:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/new:113:33: error: declaration of 'operator new []' as non-function
 void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
                                 ^
In file included from ncCheck.cpp:2:0:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/new:113:27: error: expected unqualified-id before 'unsigned'
 void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
                           ^
In file included from /opt/mxe/usr/x86_64-w64-mingw32.static/include/crtdefs.h:10:0,
                 from /opt/mxe/usr/x86_64-w64-mingw32.static/include/string.h:9,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/cstring:42,
                 from ncCheck.cpp:1:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/new:119:25: error: declaration of 'operator new' as non-function
 void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
                         ^
In file included from ncCheck.cpp:2:0:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/new:119:25: error: expected unqualified-id before 'unsigned'
 void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
                         ^
In file included from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/ext/new_allocator.h:33:0,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/x86_64-w64-mingw32.static/bits/c++allocator.h:33,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/allocator.h:46,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/string:41,
                 from ./ncException.h:2,
                 from ncCheck.cpp:3:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/new:119:33: error: expected primary-expression before 'const'
 void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
                                 ^
In file included from /opt/mxe/usr/x86_64-w64-mingw32.static/include/crtdefs.h:10:0,
                 from /opt/mxe/usr/x86_64-w64-mingw32.static/include/string.h:9,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/cstring:42,
                 from ncCheck.cpp:1:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/new:121:27: error: declaration of 'operator new []' as non-function
 void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
                           ^
In file included from ncCheck.cpp:2:0:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/new:121:27: error: expected unqualified-id before 'unsigned'
 void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
                           ^
In file included from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/ext/new_allocator.h:33:0,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/x86_64-w64-mingw32.static/bits/c++allocator.h:33,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/allocator.h:46,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/string:41,
                 from ./ncException.h:2,
                 from ncCheck.cpp:3:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/new:121:35: error: expected primary-expression before 'const'
 void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
                                   ^
In file included from /opt/mxe/usr/x86_64-w64-mingw32.static/include/crtdefs.h:10:0,
                 from /opt/mxe/usr/x86_64-w64-mingw32.static/include/string.h:9,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/cstring:42,
                 from ncCheck.cpp:1:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/new:129:32: error: declaration of 'operator new' as non-function
 inline void* operator new(std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT
                                ^
In file included from ncCheck.cpp:2:0:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/new:129:32: error: expected unqualified-id before 'unsigned'
 inline void* operator new(std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT
                                ^
In file included from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/ext/new_allocator.h:33:0,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/x86_64-w64-mingw32.static/bits/c++allocator.h:33,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/allocator.h:46,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/string:41,
                 from ./ncException.h:2,
                 from ncCheck.cpp:3:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/new:129:40: error: expected primary-expression before 'void'
 inline void* operator new(std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT
                                        ^
In file included from /opt/mxe/usr/x86_64-w64-mingw32.static/include/crtdefs.h:10:0,
                 from /opt/mxe/usr/x86_64-w64-mingw32.static/include/string.h:9,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/cstring:42,
                 from ncCheck.cpp:1:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/new:131:34: error: declaration of 'operator new []' as non-function
 inline void* operator new[](std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT
                                  ^
In file included from ncCheck.cpp:2:0:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/new:131:34: error: expected unqualified-id before 'unsigned'
 inline void* operator new[](std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT
                                  ^
In file included from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/ext/new_allocator.h:33:0,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/x86_64-w64-mingw32.static/bits/c++allocator.h:33,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/bits/allocator.h:46,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/string:41,
                 from ./ncException.h:2,
                 from ncCheck.cpp:3:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/new:131:42: error: expected primary-expression before 'void'
 inline void* operator new[](std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT
                                          ^
In file included from ncCheck.cpp:2:0:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/ext/new_allocator.h:44:14: error: expected unqualified-id before 'unsigned'
   using std::size_t;
              ^
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/ext/new_allocator.h:44:14: error: expected ';' before 'unsigned'
In file included from /opt/mxe/usr/x86_64-w64-mingw32.static/include/crtdefs.h:10:0,
                 from /opt/mxe/usr/x86_64-w64-mingw32.static/include/string.h:9,
                 from /opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/cstring:42,
                 from ncCheck.cpp:1:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/ext/new_allocator.h:44:14: error: declaration does not declare anything [-fpermissive]
   using std::size_t;
              ^
In file included from ncCheck.cpp:2:0:
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/ext/new_allocator.h: In member function '__gnu_cxx::new_allocator<_Tp>::size_type __gnu_cxx::new_allocator<_Tp>::max_size() const':
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/ext/new_allocator.h:114:16: error: expected primary-expression before 'unsigned'
       { return size_t(-1) / sizeof(_Tp); }
                ^
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/ext/new_allocator.h:114:16: error: expected ';' before 'unsigned'
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.static/5.5.0/include/c++/ext/new_allocator.h:114:16: error: expected primary-expression before 'unsigned'

У меня вопрос, что может вызвать эту проблему, где size_t, кажется, вызывает ошибку? Я исчерпал свою способность отследить проблему и мне нужны указатели.

Я проследил за заголовком и увидел, что size_t - это определение типа, определенное в файле c++config.h, например:

namespace std
{
  typedef __SIZE_TYPE__     size_t;
  typedef __PTRDIFF_TYPE__  ptrdiff_t;

#if __cplusplus >= 201103L
  typedef decltype(nullptr) nullptr_t;
#endif
}

и я вижу, что __SIZE_TYPE__ - это предопределенный макрос gcc . Содержимое __SIZE_TYPE__ выглядит так:

$ x86_64-w64-mingw32.static-g++ -dM -E - < /dev/null | grep __SIZE_TYPE__
#define __SIZE_TYPE__ long long unsigned int

Теперь, для дополнительной информации, я на самом деле пытаюсь кросс-компилировать библиотеку для Windows из Linux, но я не знаю, относится ли это к этому вопросу. В случае, если это уместно, я использую minw32-w64 для кросс-компиляции, и я на самом деле использую систему MXE , которая собирает много библиотек и т. Д. Для кросс-компиляции.

...