A5 compiled fine, but can't compile against the library
Specter Phoenix

I compiled Allegro 5 using MinGW with no problems. I was even able to compile projects fine. Then today I updated stdlib.h and wchar.h in order to make MinGW compile without error when passing -std=c++11. Oddly enough, after updating those two files and recompiling the simple display code:

1#include <stdio.h> 2#include <allegro5/allegro.h> 3 4int main(int argc, char **argv){ 5 6 ALLEGRO_DISPLAY *display = NULL; 7 8 if(!al_init()) { 9 fprintf(stderr, "failed to initialize allegro!\n"); 10 return -1; 11 } 12 13 display = al_create_display(640, 480); 14 if(!display) { 15 fprintf(stderr, "failed to create display!\n"); 16 return -1; 17 } 18 19 al_clear_to_color(al_map_rgb(0,0,0)); 20 21 al_flip_display(); 22 23 al_rest(10.0); 24 25 al_destroy_display(display); 26 27 return 0; 28}

I get 5 errors:


c:\mingw\include\allegro5\file.h|34|error: expected identifier before '*' token|
c:\mingw\include\allegro5\file.h|34|error: 'off_t' declared as function returning a function|
c:\mingw\include\allegro5\fshook.h|75|error: expected identifier before '*' token|
c:\mingw\include\allegro5\fshook.h|75|error: 'off_t' declared as function returning a function|
c:\mingw\include\allegro5\fshook.h|101|error: 'off_t' does not name a type|

The lines in question:
file.h line 34:

AL_METHOD(off_t,   fi_fsize, (ALLEGRO_FILE *f));

fshook.h line 75

AL_METHOD(off_t,           fs_entry_size,       (ALLEGRO_FS_ENTRY *e));

fshook.h line 101

AL_FUNC(off_t,                al_get_fs_entry_size,(ALLEGRO_FS_ENTRY *e));

Don't understand why it worked before and now I get these errors. The last one makes no sense since both files have typedef unsigned int off_t;.


This kind of reminds me when I tried to compile some C++11 code using a cross-compiler and produced a similar error. I fixed it by passing -std=gnu++11 instead.

Maybe I'm kind of misunderstanding but, have you tried passing -std=gnu++11 instead of the other?

Specter Phoenix

Yeah, it compiles fine with -std=gnu++11, but you have to be careful as it loads extensions that aren't part of the standard so if you use them your code may not compile under another compiler. Making it work with -std=c++11 gives me a side project to do though.

Edgar Reynaldo

For reference I'm looking at MinGW gcc and stdlib c++ 5.3.0 with mingwrt 3.21.1. I'm also assuming you're talking about the stdlib.h and the wchar.h from the MinGW users mailing list.

Did you try recompiling Allegro? And see if it still worked after your updates?

Why don't you look at the updated stdlib.h and wchar.h and see what changed? The diff program will tell you exactly what is different.

wchar.h includes sys/types.h. Both versions. wchar.h is never included by Allegro.

stdio.h includes sys/types.h as well (which you included in your program)

sys/types.h defines _off_t and off_t on lines 54 and 57.

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_ */

_NO_OLDNAMES is probably defined when -std=c++11, but I couldn't say for sure. Which would mean that off_t is undefined.

And in allegro/include/allegro5/file.h we have :

4#include "allegro5/base.h"

And in allegro/include/allegro5/base.h we have :

22#ifndef ALLEGRO_NO_STD_HEADERS 23 #include <errno.h> 24 #ifdef _MSC_VER 25 /* enable posix for limits.h and only limits.h 26 enabling it for all msvc headers will potentially 27 disable a lot of commonly used msvcrt functions */ 28 #define _POSIX_ 29 #include <limits.h> 30 #undef _POSIX_ 31 #else 32 #include <limits.h> 33 #endif 34 #include <stdarg.h> 35 #include <stddef.h> 36 #include <stdlib.h> 37 #include <time.h> 38 #include <string.h> 39 #include <sys/types.h> 40#endif

So if standard headers are included (#ifndef ALLEGRO_NO_STD_HEADERS) we have sys/types.h included, but it doesn't define off_t in the case of _NO_OLDNAMES, so file.h won't compile.

In the case of fshook.h it's a little different :

19#include "allegro5/base.h" 20#include "allegro5/file.h" 21#include "allegro5/path.h" 22 23#ifdef ALLEGRO_HAVE_SYS_TYPES_H 24 #include <sys/types.h> 25#else 26/* 4 Gig max offsets if sys/types doesn't exist. */ 27typedef unsigned int off_t; 28#endif

Considering that MinGW has sys/types.h, it would make sense to assume that ALLEGRO_HAVE_SYS_TYPES_H would be defined, and therefore sys/types.h would be included (which doesn't define off_t in the case of _NO_OLDNAMES), leaving off_t undefined.

That would explain both cases in your compile test, as long as _NO_OLDNAMES is undefined it will work, but when it is, it won't.

The real difference here is compiling with -std=c++11. It has nothing to do with any of the changes in the headers. Try compiling with and without the c++11 flag. It should work without it, and fail with it.

Specter Phoenix

That was the problem.

Thread #616488. Printed from Allegro.cc