0

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.

crobar
  • 2,810
  • 4
  • 28
  • 46
  • 4
    The problem is most likely not in GCC or the C++ standard library. Even if the error happens in a system header file, it's infinitely more likely that the root of the problem lies in the code you try to build. – Some programmer dude Jun 27 '18 at 12:55
  • @Someprogrammerdude, I'm sure that's the case, but I have no idea how to track down the error! – crobar Jun 27 '18 at 12:57
  • 1
    @crobar Look here https://stackoverflow.com/q/3742822/451600 The output from the preprocessor should make it a lot easier to track down. Pull it in to an editor and format + compile the code. – Captain Giraffe Jun 27 '18 at 13:02
  • 3
    From your preprocessor run, perhaps you should look for something like `#define size_t`? More importantly, perhaps check for such a macro definition in the library you attempt to build? – Some programmer dude Jun 27 '18 at 13:04
  • 1
    @Someprogrammerdude, indeed, there is a `#define size_t unsigned __int64` which comes from a header file `netcdf.h` which is wrapped in a test `#if defined (_WIN64)` I guess this should actually be `#if defined (MSVC) & defined (_WIN64)` or something along these lines. This is actually a C header file (the netcdf library is a C library, so maybe the extra check should just be for `__cplusplus` – crobar Jun 27 '18 at 13:14
  • Well better us `&&` instead of `&`. :) Besides that I would argue it's an error in general to have it defined in a library header file like that, but yeah adding the extra check for the MSVC compiler should be a good start. *And* reporting this as a bug for the library maintainers. – Some programmer dude Jun 27 '18 at 13:21
  • 1
    @crobar - Using `#if defined (MSVC)` is just hiding the problem for g++. It would still be wrong for any Visual Studio from this millennium. – Bo Persson Jun 27 '18 at 13:32
  • @Someprogrammerdude, I'll inform the developers of the issue! – crobar Jun 27 '18 at 13:36
  • @BoPersson, could you point me in the right direction for what it should be? – crobar Jun 27 '18 at 13:36
  • @crobar - My guess is that this is old stuff that could just be removed. – Bo Persson Jun 27 '18 at 13:41
  • @BoPersson, actually I looked, and there is a newer version which does not have this, MXE does not have this version yet, but I can work around it for now – crobar Jun 27 '18 at 14:43

0 Answers0