[A5] Will not compile; warning C4627 '#include <allegro.h>': skipped when lookin
Molleby

As the topic says...

I've followed the installation instructions for Allegro 5 and Visual C++ 2010 and tried to compile this code, as instructed:

Quote:

#define USE_CONSOLE
#include <allegro.h>

int main()
{
allegro_init();
install_keyboard();

set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);

triangle(screen, 320, 40, 147, 340, 493, 340, makecol(255, 0, 0));
circlefill(screen, 320, 240, 100, makecol(255, 255, 255));

while(!key[KEY_ESC])
;

return 0;
}

END_OF_MAIN();

however, I get this warning:

warning C4627: '#include <allegro.h>': skipped when looking for precompiled header

So, what could I have done wrong?

Elias

Allegro 5 and Allegro 4 are two completely different libraries. To compile that code you want the latest Allegro 4, not Allegro 5.

Molleby

Damn, you are of course right...

Ok, I then tried with this...

Quote:

#include <allegro5/allegro.h>
#include <stdio.h>
#include <stdAfx.h> //because the compiler asked me if I had remembered it

int main(int argc, char **argv)
{
ALLEGRO_DISPLAY *display = NULL;

if(!al_init()) {
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}

display = al_create_display(640, 480);
if(!display) {
fprintf(stderr, "failed to create display!\n");
return -1;
}

al_clear_to_color(al_map_rgb(0,0,0));
al_flip_display();
al_rest(10.0);
al_destroy_display(display);

return 0;

}

Now I get a bunch of errors:
error C2065: 'ALLEGRO_DISPLAY' : undeclared identifier
error C2065: 'display' : undeclared identifier
error C3861: 'al_init': identifier not found
error C2065: 'display' : undeclared identifier
error C3861: 'al_create_display': identifier not found
error C2065: 'display' : undeclared identifier
error C3861: 'al_clear_to_color': identifier not found
error C3861: 'al_map_rgb': identifier not found
error C3861: 'al_flip_display': identifier not found
error C3861: 'al_rest': identifier not found
error C2065: 'display' : undeclared identifier
error C3861: 'al_destroy_display': identifier not found

I just know I'm making some obviously stupid mistake :(

X-G
Quote:

#include <stdAfx.h> //because the compiler asked me if I had remembered it

Why are you using precompiled headers if you don't know how they work?

Hint: The PCH must always be included first. But really, you're better off not using them if you don't know how they work.

Molleby

I was in a hurry and didn't want to burden my brain with additional weight, so I just did what the compiler hinted at. And yes, I am a noob, or whatever its called :-/

Edit: do the error messages have something to do with an inability to link to the proper allegro library?

X-G

Nope, those are compiler errors. Linking is a later step.

Molleby

I see. Will try and install it all again and see if something changes.

Edgar Reynaldo

All of the functions and symbols that were named in your errors belong to allegro5/allegro.h. So either your compiler didn't find allegro5/allegro.h due to it being in a different directory (not in your compiler's include directory) or you got a bad header somehow. It's most likely the first explanation.

When you download the binaries, you need to :
1) Copy the contents of allegro/include to your compiler's include directory.
2) Copy the contents of allegro/lib to your compiler's lib directory.
3) Copy the contents of allegro/bin to your executable's directory or to your system directory.

You can skip the first two steps if you set your project settings to use allegro/include as a search directory for your compiler, and to use allegro/lib as a linker search directory. You will also need to link to the appropriate link libraries.

X-G

It's most likely the first explanation.

No, I already explained why. He put the PCH too late in the include chain. Everything before the PCH is ignored by the compiler. Allegro.h was never included.

Edgar Reynaldo

Oh, sorry about that. What's the reasoning behind that though? I mean, why do precompiled headers go first, and how would the compiler know they're precompiled if they still have a .h extension?

Thomas Fjellstrom

Since the PCH comes first, it can ignore other headers that were part of the PCH?

X-G

I mean, why do precompiled headers go first, and how would the compiler know they're precompiled if they still have a .h extension?

The compiler knows beforehand from the flags passed to it what the name of the PCH is (and there can only ever be at most one PCH). It expects it first because of how PCHs work by definition: the contents of the PCH is always available, in every compilation unit, before anything else in that compilation unit is looked at.

The question you should be asking is "Why do I have to include the PCH at all if it's always present?" The answer is 1) explicit is better than implicit, and 2) it allows you disable use of the PCH and still have your program compile equivalently.

Molleby

Ok, I reinstalled everything and put the monolith-static-mt-debug.lib (read that it would be easier) into Additional Dependencies. And I dropped the precompiled header.

My codes now looks like this

Quote:

#include <allegro5/allegro.h>
#include <stdio.h>

int main(int argc, char **argv)
{
ALLEGRO_DISPLAY *display = NULL;

if(!al_init()) {
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}

display = al_create_display(640, 480);
if(!display) {
fprintf(stderr, "failed to create display!\n");
return -1;
}

al_clear_to_color(al_map_rgb(0,0,0));
al_flip_display();
al_rest(10.0);
al_destroy_display(display);

return 0;

}

I compile it and now I get these errors:

Quote:

LINK : error LNK2001: unresolved external symbol _mainCRTStartup
C:\Documents and settings\Louise Skovrup\Dokumenter\AllegroTestrun\Frontier\Debug\Frontier.exe : fatal error LNK1120: 1 unresolved externals

Edit: I also tried to insert #define ALLEGRO_STATICLINK in the beginning of the code, but got the same errors

LennyLen

Try switching to a GUI (Win32) application instead of a Console application.

Molleby

Tried to switch to Win32 instead of Console

Now the error message says:

Quote:

LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
C:\Documents and settings\Louise Skovrup\Dokumenter\AllegroTestrun\Frontier\Debug\Frontier.exe : fatal error LNK1120: 1 unresolved externals

torhu

Almost looks like you've created a DLL or library project. Make sure it's a console project.

Molleby

I'm 99% sure that I've created a proper console project.

I've googled this problem A LOT (spent hours on this :-[) and some posters seem to think that this error has something to do with UNICODE. Is that possible?

Maybe I should just give up on Visual 2010... what's a good substitute?

Elias

Not sure, but maybe wrong libraries could cause this.

Double check you downloaded the right file on http://www.allegro.cc/files/ (use MSVC 10 and not any of the others) and make sure you only added the allegro-5.0.0-monolith-mt-debug.lib (or allegro-5.0.0-monolith-mt.lib) to your linker settings and none of the other libraries.

torhu

I haven't got msvc 10 (still on 9), but if someone uploads a project config that you could use, that might fix the problem. Might be something funny with your msvc default project settings or something.

EDIT: You could check that there's no UNICODE or _UNICODE #defines in the project settings (C/C++ -> Preprocessor).

Molleby

I gave up on Visual 2010 and installed Code::Blocks. Works perfectly with Allegro 5.

Elias

MSVC 10 definitely works as well. I downloaded A5 at work, selected 2010 project in cmake. Then opened the project with VC 2010 express and compiled. And had working examples.

X-G

It definitely works, my current home projects are all A5+MSVC10.

Thread #606413. Printed from Allegro.cc