I'm attempting to build the netcdf-cxx4 library and encountering an odd error which is showing up in char_traits.h, a libstdc++ header. The first error is below:
>> $ 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);
The full error:
$ 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'
My question is, what could possibly cause this problem, where size_t
seems to be causing the error? I've exhausted my ability to track down the problem and need some pointers.
I followed the trail of headers and see that size_t
is a typedef defined in a file c++config.h
like so:
namespace std
{
typedef __SIZE_TYPE__ size_t;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
#if __cplusplus >= 201103L
typedef decltype(nullptr) nullptr_t;
#endif
}
and I see that __SIZE_TYPE__
is a gcc predefined macro. The contents of __SIZE_TYPE__
appears to be this:
$ x86_64-w64-mingw32.static-g++ -dM -E - < /dev/null | grep __SIZE_TYPE__
#define __SIZE_TYPE__ long long unsigned int
Now, for extra info, I'm actually attempting to cross compile the library for windows from Linux, but I don't know if this is relevant to the question. In case it is relevant I am using minw32-w64 for the cross compile, and I'm actually using the MXE system which builds many libraries etc for cross-compiling.