Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro 5 include file rejected

Credits go to Dennis for helping out!
This thread is locked; no one can reply to it. rss feed Print
Allegro 5 include file rejected
RazorSharpFang
Member #14,438
July 2012

Interestingly, an include file of mine has been rejected by my compiler.

The file is "allegro_image.h".

My compiler says that al_init_image_addon and al_shutdown_image_addon have not been declared. I am using the static version of Allegro 5.0.7.
Allegro works absolutely fine without this one, though I kinda need it to draw bitmaps... :|

After those complaints, it goes on to say "expected constructors, destructors of '{
' before ';', but I think that's just because it didn't recognise the functions.
I would diagnose these, but I don't understand the #ifndef and other stuff in the file...

I have been using Code::blocks and the mingw g++ compiler, and nothing has gone wrong so far. (since I started using an IDE)

Please help, I can't draw any bitmaps until I get this working...

LennyLen
Member #5,313
December 2004
avatar

Please post your code.

RazorSharpFang
Member #14,438
July 2012

allegro_image.h -> This file has been unedited from it's download and install

#SelectExpand
1#ifndef __al_included_allegro5_allegro_image_h 2#define __al_included_allegro5_allegro_image_h 3 4#if (defined ALLEGRO_MINGW32) || (defined ALLEGRO_MSVC) || (defined ALLEGRO_BCC32) 5 #ifndef ALLEGRO_STATICLINK 6 #ifdef ALLEGRO_IIO_SRC 7 #define _ALLEGRO_IIO_DLL __declspec(dllexport) 8 #else 9 #define _ALLEGRO_IIO_DLL __declspec(dllimport) 10 #endif 11 #else 12 #define _ALLEGRO_IIO_DLL 13 #endif 14#endif 15 16#if defined ALLEGRO_MSVC 17 #define ALLEGRO_IIO_FUNC(type, name, args) _ALLEGRO_IIO_DLL type __cdecl name args 18#elif defined ALLEGRO_MINGW32 19 #define ALLEGRO_IIO_FUNC(type, name, args) extern type name args 20#elif defined ALLEGRO_BCC32 21 #define ALLEGRO_IIO_FUNC(type, name, args) extern _ALLEGRO_IIO_DLL type name args 22#else 23 #define ALLEGRO_IIO_FUNC AL_FUNC 24#endif 25 26 27#ifdef __cplusplus 28extern "C" { 29#endif 30 31 32ALLEGRO_IIO_FUNC(bool, al_init_image_addon, (void)); 33ALLEGRO_IIO_FUNC(void, al_shutdown_image_addon, (void)); 34ALLEGRO_IIO_FUNC(uint32_t, al_get_allegro_image_version, (void)); 35 36 37#ifdef __cplusplus 38} 39#endif 40 41#endif

Hope that helps

Matthew Leverton
Supreme Loser
January 1999
avatar

That's not your code. Your code looks exactly like:

#include <allegro5/allegro_image.h>

RazorSharpFang
Member #14,438
July 2012

Exactly, and that is the code that is throwing the error!
If I remove the link to the allegro_image.h file, it works fine!
But here's mine, single file, main.cpp.

#SelectExpand
1#define ALLEGRO_STATICLINK 2// ^ needed, below are includes 3#include "allegro5/allegro_image.h" //image library throwing errors 4#include "allegro5/allegro.h" //main allegro library. No errors here. 5#include <iostream> 6#include <stdio.h> 7#include <stdlib.h> 8using namespace std; 9// ^ I think I need that... dunno why... 10void AbortGame(const char* message); 11//avoids redundancy, abort game after message display 12ALLEGRO_DISPLAY* SetUpDisplay(); 13//set the display to fullscreen, no res change, handles keyboard, mouse, and others... 14//returns ONLY the display 15ALLEGRO_TIMER* SetUpTimer(); 16//sets up the timer, ticks 60 times each frame... 17FILE* SetUpLog(); 18//prepares the log file for logging... 19void Message(const char *input); 20//standard message, output to terminal, and out to the log file as well. Useful for debugging... 21ALLEGRO_BITMAP* SetUpScreenBuffer(); 22// Returns the screen buffer which will be used for resolution independace. Write to this, then write this 23// to the screen after finished drawing. Scale as needed. 24//START GLOBAL VARIABLES 25FILE *log; //log file. Write messages to this for debugging 26ALLEGRO_DISPLAY *display; //the main display. 27ALLEGRO_BITMAP *screenBuffer; //screen buffer 28ALLEGRO_TIMER *timer; //umm... timer? 29int screenWidth, screenHeight, scaleX, scaleY, scaleW, scaleH;//global scaling variables. 30int main(int argc, char **argv) 31{ 32 log = SetUpLog(); 33 display = SetUpDisplay(); 34 screenWidth = al_get_display_width(display); 35 screenHeight = al_get_display_height(display); 36 screenBuffer = SetUpScreenBuffer(); 37 timer = SetUpTimer(); 38 al_flip_display(); 39 //al_init_image_addon(void); 40 while(true) //main game-loop. should never return until game close 41 { 42 Sleep(3000); 43 AbortGame("Success!\n"); 44 } 45} 46 47ALLEGRO_TIMER* SetUpTimer() 48{ 49 ALLEGRO_TIMER* time = al_create_timer(1.0 / 60); 50 if (!time) { 51 AbortGame("Failed to create timer\n"); 52 } 53 Message("Timer created successfully\n"); 54 return time; 55} 56 57ALLEGRO_DISPLAY* SetUpDisplay() 58{ 59 ALLEGRO_DISPLAY *disp = NULL; 60 ALLEGRO_DISPLAY_MODE disp_data; 61 if(!al_init()) { 62 AbortGame("Allegro Error, fatal.\n"); 63 } 64 Message("Allegro Initialized Successfully\n"); 65 if (!al_install_keyboard()) { 66 AbortGame("Failed to install keyboard\n"); 67 } 68 Message("Keyboard initialized successfully\n"); 69 if (!al_install_mouse()) { 70 AbortGame("Failure to install mouse\n"); 71 } 72 Message("Mouse initialized successfully\n"); 73 al_get_display_mode(al_get_num_display_modes() - 1, &disp_data); 74 Message("Display resolution enunciated successfully: width:"); 75 char buffer[8]; 76 sprintf(buffer,"%d",disp_data.width); 77 Message(buffer); 78 Message(" height: "); 79 sprintf(buffer,"%d",disp_data.height); 80 Message(buffer); 81 Message("\n"); 82 al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW); 83 disp = al_create_display(disp_data.width, disp_data.height); 84 if (!disp) { 85 AbortGame("Failed to create display"); 86 } 87 Message("Display created successfully, width:"); 88 sprintf(buffer,"%d",al_get_display_width(disp)); 89 Message(buffer); 90 Message(" height: "); 91 sprintf(buffer,"%d",al_get_display_height(disp)); 92 Message(buffer); 93 Message("\n"); 94 al_clear_to_color(al_map_rgb(0,0,0)); 95 return disp; 96} 97 98void AbortGame(const char* message) 99{ 100 printf("%s \n", message); 101 fprintf(log, "%s \n", message); 102 fclose(log); 103 exit(1); 104} 105 106FILE* SetUpLog() 107{ 108 FILE *fp = NULL; 109 fp = fopen("log.log","w"); 110 fprintf(fp, "Game started\n"); 111 printf("Game started\n"); 112 return fp; 113} 114 115void Message(const char* message) 116{ 117 printf(message); 118 fprintf(log,message); 119 return; 120} 121 122ALLEGRO_BITMAP* SetUpScreenBuffer() 123{ 124 ALLEGRO_BITMAP *buffer = al_create_bitmap(1080,1920); 125 int sx = screenWidth/1920; 126 int sy = screenHeight/1080; 127 int scale = std::min(sx,sy); 128 scaleW = 1920 * scale; 129 scaleH = 1080 * scale; 130 scaleX = (screenWidth - scaleW) / 2; 131 scaleY = (screenWidth - scaleH) / 2; 132}

Dennis
Member #1,090
July 2003
avatar

Exchange lines 3 and 4, so that allegro.h is included first.

weapon_S
Member #7,859
October 2006
avatar

RazorSharpFang
Member #14,438
July 2012

Yep, that was it.
I had no idea that the order of includes could affect building...
Then again, I've never had more than 3 include files before...

Many thanks for your quick help, you guys are awesome, just sayin'.

Keep it awesome!
RazorSharpFang

LennyLen
Member #5,313
December 2004
avatar

I had no idea that the order of includes could affect building...

When the preprocessor includes files, it copies the contents of them into the file that was including them, putting them where the directive was written. This is why the order is important.

Dennis
Member #1,090
July 2003
avatar

You should give credit to everyone who helped.

Also please try to make an effort to investigate and understand what's going on and WHY you needed to make that change.

RazorSharpFang
Member #14,438
July 2012

Oh. That's what credit means! (I understand now!)

Incidentally, I did manage to get it to compile, but after editing the allegro_image.h file a lot, which would probably impede it's cross-platform nature.

I suspect now that the allegro.h or the include of allegro.h have #defines which would change the preprocessor's output, which would cause differences if the files were included in a different order.
Wow, I'm learning a lot from this. I should come here more often.

weapon_S
Member #7,859
October 2006
avatar

after editing the allegro_image.h file a lot

You normally shouldn't do that. Especially if you want to use it again :P You can set the directory where GCC searches for include files with -I.

Quote:

I suspect now

It's much simpler than that.

Luiji99
Member #12,254
September 2010

Actually, he's exactly right as to why they need to be included in that order. allegro_image.h requires ALLEGRO_MSVC to be defined if it is running on Microsoft's compiler while utilizing DLLs. If allegro.h is included, then platform/almsvc.h will be automatically included through Allegro's internal/ header-set. If allegro_image.h is included before allegro.h, it does not recognize that it must use a declspec to declare the functions and, thus, MSVC assumes that it must be declared inside of the executable and this results in a not-defined error.

Programming should be fun. That's why I hate Java.

Go to: