我正在尝试构建netcdf-cxx4库,遇到一个奇怪的错误,该错误显示在libstdc ++头char_traits.h中。第一个错误如下:
>> $ 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
中定义的typedef,如下所示:
namespace std
{
typedef __SIZE_TYPE__ size_t;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
#if __cplusplus >= 201103L
typedef decltype(nullptr) nullptr_t;
#endif
}
,我看到__SIZE_TYPE__
是gcc predefined macro。 __SIZE_TYPE__
的内容似乎是这样的:
$ x86_64-w64-mingw32.static-g++ -dM -E - < /dev/null | grep __SIZE_TYPE__
#define __SIZE_TYPE__ long long unsigned int
现在,有关更多信息,我实际上是试图从Linux交叉编译Windows的库,但是我不知道这是否与问题有关。如果相关,我将使用minw32-w64进行交叉编译,而实际上我使用的是MXE系统,该系统可构建许多库等用于交叉编译。