<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Allegro compilation error with MinGW C++11, sys/types.h, off_t, and _fsize_t</title>
		<link>http://www.allegro.cc/forums/view/616526</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 28 Oct 2016 11:12:05 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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.</p><p>This issue was first brought up here by SpecterPhoenix :<br /><a href="https://www.allegro.cc/forums/thread/616488">https://www.allegro.cc/forums/thread/616488</a></p><p>mingw/include/sys/types.h defines off_t, but only in certain cases.</p><p>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 :
</p><div class="source-code"><div class="toolbar"><span class="name">mingwrt 3.21.1 sys/types.h</span><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 52</span><span class="p">#ifndef  _OFF_T_</span>
<span class="number"> 53</span><span class="p">#define  _OFF_T_</span>
<span class="number"> 54</span><span class="k1">typedef</span> <span class="k1">long</span> _off_t<span class="k2">;</span>
<span class="number"> 55</span>
<span class="number"> 56</span><span class="p">#ifndef  _NO_OLDNAMES</span>
<span class="number"> 57</span><span class="k1">typedef</span> _off_t  off_t<span class="k2">;</span>
<span class="number"> 58</span><span class="p">#endif</span>
<span class="number"> 59</span><span class="p">#endif  /* Not _OFF_T_ */</span>
</div></div><p>

</p><div class="source-code"><div class="toolbar"><span class="name">mingwrt 3.22.2 sys/types.h</span><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 69</span><span class="p"># if _POSIX_C_SOURCE</span>
<span class="number"> 70</span>  <span class="c">/* ...but note that this form should ALWAYS be preferred when</span>
<span class="number"> 71</span><span class="c">   * compiling POSIX compatible source code.</span>
<span class="number"> 72</span><span class="c">   */</span>
<span class="number"> 73</span>  <span class="k1">typedef</span> _off_t  off_t<span class="k2">;</span>
<span class="number"> 74</span><span class="p"># endif</span>
</div></div><p>

Allegro uses off_t in the following files :
</p><pre>
c:\LIBS5302Build\A5211\allegro\src&gt;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)
</pre><p>

And uses off_t in the following headers :
</p><pre>
c:\LIBS5302Build\A5211\allegro\include&gt;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));
</pre><p>

In file.h it includes allegro/base.h, which includes sys/types.h. fshook.h also includes sys/types.h. See <a href="https://www.allegro.cc/forums/thread/616488/1025136#target">https://www.allegro.cc/forums/thread/616488/1025136#target</a> for details.</p><p>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.</p><p>I&#39;m not sure how to go about implementing that.</p><p>There&#39;s also a problem with _fsize_t being undefined when compiling as C++11 but I haven&#39;t had the chance to investigate that yet.</p><p><b>EDIT</b><br />Keith Marshall has issued a patch to address these issues. They are both fixed in mingwrt 3.22.3.</p><p>There are further issues when compiling an allegro program as C++11 code. The following errors also occur :</p><pre>
||=== Build: Release in Allegro5_backend (compiler: GNU GCC Compiler) ===|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|177|error: &#39;::wcscat&#39; has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|178|error: &#39;::wcscmp&#39; has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|179|error: &#39;::wcscoll&#39; has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|180|error: &#39;::wcscpy&#39; has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|181|error: &#39;::wcscspn&#39; has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|183|error: &#39;::wcslen&#39; has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|184|error: &#39;::wcsncat&#39; has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|185|error: &#39;::wcsncmp&#39; has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|186|error: &#39;::wcsncpy&#39; has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|188|error: &#39;::wcsspn&#39; has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|193|error: &#39;::wcstok&#39; has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|196|error: &#39;::wcsxfrm&#39; has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|204|error: &#39;::wcschr&#39; has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|205|error: &#39;::wcspbrk&#39; has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|206|error: &#39;::wcsrchr&#39; has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|207|error: &#39;::wcsstr&#39; has not been declared|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar||In function &#39;wchar_t* std::wcschr(wchar_t*, wchar_t)&#39;:|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|213|error: invalid conversion from &#39;const wchar_t*&#39; to &#39;wchar_t*&#39; [-fpermissive]|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|212|note:   initializing argument 1 of &#39;wchar_t* std::wcschr(wchar_t*, wchar_t)&#39;|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar||In function &#39;wchar_t* std::wcspbrk(wchar_t*, const wchar_t*)&#39;:|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|217|error: invalid conversion from &#39;const wchar_t*&#39; to &#39;wchar_t*&#39; [-fpermissive]|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|216|note:   initializing argument 1 of &#39;wchar_t* std::wcspbrk(wchar_t*, const wchar_t*)&#39;|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar||In function &#39;wchar_t* std::wcsrchr(wchar_t*, wchar_t)&#39;:|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|221|error: invalid conversion from &#39;const wchar_t*&#39; to &#39;wchar_t*&#39; [-fpermissive]|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|220|note:   initializing argument 1 of &#39;wchar_t* std::wcsrchr(wchar_t*, wchar_t)&#39;|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar||In function &#39;wchar_t* std::wcsstr(wchar_t*, const wchar_t*)&#39;:|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|225|error: invalid conversion from &#39;const wchar_t*&#39; to &#39;wchar_t*&#39; [-fpermissive]|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar|224|note:   initializing argument 1 of &#39;wchar_t* std::wcsstr(wchar_t*, const wchar_t*)&#39;|
c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\char_traits.h|358|error: &#39;wcslen&#39; was not declared in this scope|
||=== Build finished: 21 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

</pre><p>

I am researching the cause of these errors as we speak.</p><p><b>EDIT</b><br />These errors are caused by #including &lt;string.h&gt; before &lt;string&gt;. You can fix them by including &lt;string&gt; before &lt;string.h&gt;. There will probably be a patch issued to fix this as well.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 17 Oct 2016 02:59:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>To be clear, are these compiler bugs that are getting fixed, or bugs in Allegro?</p><p><tt>string</tt> is a C++ header while <tt>string.h</tt> is a C header. I believe there should be a <tt>cstring</tt> header for C++ instead that replaces <tt>string.h</tt> 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.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Mon, 17 Oct 2016 09:18:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>These are compiler bugs for the most part. Allegro&#39;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.</p><p>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.</p><p><b>EDIT</b><br />Keith Marshall has written a patch for these issues.</p><p>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.</p><p><a href="https://sourceforge.net/projects/mingw/files/MinGW/Base/mingwrt/mingwrt-3.22/">https://sourceforge.net/projects/mingw/files/MinGW/Base/mingwrt/mingwrt-3.22/</a></p><p><a href="https://www.allegro.cc/files/attachment/610588">wchar.h</a><br /><a href="https://www.allegro.cc/files/attachment/610589">wchar.h.patch</a></p><p>mingwrt3.22.4 will probably be released sometime to address these issues as well.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Tue, 18 Oct 2016 02:16:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>nice
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (neesha diwakar)</author>
		<pubDate>Fri, 28 Oct 2016 11:12:05 +0000</pubDate>
	</item>
</rss>
