Allegro compilation error with MinGW C++11, sys/types.h, off_t, and _fsize_t
Edgar Reynaldo

I upgraded my MinGW 5.3.0-2 package to use mingwrt 3.22 and w32api 3.18 and now Allegro programs fail to build with the C++11 standard and an error saying off_t is undefined.

This issue was first brought up here by SpecterPhoenix :

mingw/include/sys/types.h defines off_t, but only in certain cases.

With mingwrt 3.21.1, off_t is undefined when _NO_OLDNAMES is defined. With mingwrt 3.22.2, off_t is only defined when _POSIX_C_SOURCE is defined :

mingwrt 3.21.1 sys/types.h#SelectExpand
52#ifndef _OFF_T_ 53#define _OFF_T_ 54typedef long _off_t; 55 56#ifndef _NO_OLDNAMES 57typedef _off_t off_t; 58#endif 59#endif /* Not _OFF_T_ */

mingwrt 3.22.2 sys/types.h#SelectExpand
69# if _POSIX_C_SOURCE 70 /* ...but note that this form should ALWAYS be preferred when 71 * compiling POSIX compatible source code. 72 */ 73 typedef _off_t off_t; 74# endif

Allegro uses off_t in the following files :

c:\LIBS5302Build\A5211\allegro\src>grep -r -E -I -n off_t .*.*
.\android/android_apk_file.c:273:static off_t file_apk_fsize(ALLEGRO_FILE *f)
.\android/android_apk_fs.c:144:static off_t fs_apk_entry_size(ALLEGRO_FS_ENTRY *fse)
.\file_slice.c:180:static off_t slice_fsize(ALLEGRO_FILE *f)
.\file_stdio.c:333:static off_t file_stdio_fsize(ALLEGRO_FILE *f)
.\fshook.c:108:off_t al_get_fs_entry_size(ALLEGRO_FS_ENTRY *e)
.\fshook_stdio.c:467:static off_t fs_stdio_entry_size(ALLEGRO_FS_ENTRY *fp)

And uses off_t in the following headers :

c:\LIBS5302Build\A5211\allegro\include>grep -r -E -I -n off_t .*.*
.\allegro5/file.h:34:   AL_METHOD(off_t,   fi_fsize, (ALLEGRO_FILE *f));
.\allegro5/fshook.h:27:typedef unsigned int off_t;
.\allegro5/fshook.h:75:   AL_METHOD(off_t,           fs_entry_size,       (ALLEGRO_FS_ENTRY *e));
.\allegro5/fshook.h:101:AL_FUNC(off_t,                al_get_fs_entry_size,(ALLEGRO_FS_ENTRY *e));

In file.h it includes allegro/base.h, which includes sys/types.h. fshook.h also includes sys/types.h. See for details.

We can fix this by defining _POSIX_C_SOURCE in the latest version of MinGW when off_t and sys/types.h is needed, as in base.h and fshook.h.

I'm not sure how to go about implementing that.

There's also a problem with _fsize_t being undefined when compiling as C++11 but I haven't had the chance to investigate that yet.

Keith Marshall has issued a patch to address these issues. They are both fixed in mingwrt 3.22.3.

There are further issues when compiling an allegro program as C++11 code. The following errors also occur :

||=== Build: Release in Allegro5_backend (compiler: GNU GCC Compiler) ===|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|177|error: '::wcscat' has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|178|error: '::wcscmp' has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|179|error: '::wcscoll' has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|180|error: '::wcscpy' has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|181|error: '::wcscspn' has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|183|error: '::wcslen' has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|184|error: '::wcsncat' has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|185|error: '::wcsncmp' has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|186|error: '::wcsncpy' has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|188|error: '::wcsspn' has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|193|error: '::wcstok' has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|196|error: '::wcsxfrm' has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|204|error: '::wcschr' has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|205|error: '::wcspbrk' has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|206|error: '::wcsrchr' has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|207|error: '::wcsstr' has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar||In function 'wchar_t* std::wcschr(wchar_t*, wchar_t)':|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|213|error: invalid conversion from 'const wchar_t*' to 'wchar_t*' [-fpermissive]|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|212|note:   initializing argument 1 of 'wchar_t* std::wcschr(wchar_t*, wchar_t)'|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar||In function 'wchar_t* std::wcspbrk(wchar_t*, const wchar_t*)':|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|217|error: invalid conversion from 'const wchar_t*' to 'wchar_t*' [-fpermissive]|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|216|note:   initializing argument 1 of 'wchar_t* std::wcspbrk(wchar_t*, const wchar_t*)'|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar||In function 'wchar_t* std::wcsrchr(wchar_t*, wchar_t)':|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|221|error: invalid conversion from 'const wchar_t*' to 'wchar_t*' [-fpermissive]|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|220|note:   initializing argument 1 of 'wchar_t* std::wcsrchr(wchar_t*, wchar_t)'|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar||In function 'wchar_t* std::wcsstr(wchar_t*, const wchar_t*)':|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|225|error: invalid conversion from 'const wchar_t*' to 'wchar_t*' [-fpermissive]|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|224|note:   initializing argument 1 of 'wchar_t* std::wcsstr(wchar_t*, const wchar_t*)'|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\char_traits.h|358|error: 'wcslen' was not declared in this scope|
||=== Build finished: 21 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

I am researching the cause of these errors as we speak.

These errors are caused by #including <string.h> before <string>. You can fix them by including <string> before <string.h>. There will probably be a patch issued to fix this as well.


To be clear, are these compiler bugs that are getting fixed, or bugs in Allegro?

string is a C++ header while string.h is a C header. I believe there should be a cstring header for C++ instead that replaces string.h and maintains full compatibility with C++. Not sure if that is the issue here, but it sounds suspect to include the .h in a C++ program.

Edgar Reynaldo

These are compiler bugs for the most part. Allegro's use of off_t is dubious as mentioned on the mailing list but it works for now as of mingwrt3.22.3. The rest of the errors should be fixed soon.

Re: string.h vs cstring I already checked that out. The bug persists, because cstring includes string.h as most of the c++ headers simply wrap the C lib headers.

Keith Marshall has written a patch for these issues.

If you have problems compiling allegro programs with the c++11 standard such as with off_t, _fsize_t, or wcs* functions not being declared, mingwrt3.22.3 along with the patch or header below will fix those.


mingwrt3.22.4 will probably be released sometime to address these issues as well.

neesha diwakar


Thread #616526. Printed from