Allegro 5 msvc 8
Malinus

I finally decided to try the new fancy API called "allegro 5", everybody seems to be talking about ;). But when trying to compile I get all the unresolved external errors. So there is something wrong with my linking I just don´t know what.

It´s a clean project and I link to all the libraries

(additional dependencies: allegro-static-4.9.16.lib allegro_audio-static-4.9.16.lib allegro_color-static-4.9.16.lib allegro_dialog-static-4.9.16.lib allegro_flac-static-4.9.16.lib allegro_font-static-4.9.16.lib allegro_image-static-4.9.16.lib allegro_memfile-static-4.9.16.lib allegro_physfs-static-4.9.16.lib allegro_primitives-static-4.9.16.lib allegro_ttf-static-4.9.16.lib allegro_vorbis-static-4.9.16.lib FLAC.lib freetype.lib jpeg.lib ogg.lib physfs.lib png.lib vorbis.lib vorbisfile.lib zlib.lib).

And yes I have all the files in the VC folder. And yes I am using the msvc bin.
Do I need to add some additional options or something?

Trent Gamblin

How about telling us the errors :P

Malinus
MSVC said:

1>------ Build started: Project: allegro 5, Configuration: Debug Win32 ------
1>Linking...
1>sad.obj : error LNK2019: unresolved external symbol __imp__al_wait_for_event referenced in function "int __cdecl _mangled_main(int,char * * const)" (?_mangled_main@@YAHHQAPAD@Z)
1>sad.obj : error LNK2019: unresolved external symbol __imp__al_register_event_source referenced in function "int __cdecl _mangled_main(int,char * * const)" (?_mangled_main@@YAHHQAPAD@Z)
1>sad.obj : error LNK2019: unresolved external symbol __imp__al_get_keyboard_event_source referenced in function "int __cdecl _mangled_main(int,char * * const)" (?_mangled_main@@YAHHQAPAD@Z)
1>sad.obj : error LNK2019: unresolved external symbol __imp__al_create_event_queue referenced in function "int __cdecl _mangled_main(int,char * * const)" (?_mangled_main@@YAHHQAPAD@Z)
1>sad.obj : error LNK2019: unresolved external symbol __imp__al_flip_display referenced in function "int __cdecl _mangled_main(int,char * * const)" (?_mangled_main@@YAHHQAPAD@Z)
1>sad.obj : error LNK2019: unresolved external symbol __imp__al_draw_text referenced in function "int __cdecl _mangled_main(int,char * * const)" (?_mangled_main@@YAHHQAPAD@Z)
1>sad.obj : error LNK2019: unresolved external symbol __imp__al_set_blender referenced in function "int __cdecl _mangled_main(int,char * * const)" (?_mangled_main@@YAHHQAPAD@Z)
1>sad.obj : error LNK2019: unresolved external symbol __imp__al_map_rgba_f referenced in function "int __cdecl _mangled_main(int,char * * const)" (?_mangled_main@@YAHHQAPAD@Z)
1>sad.obj : error LNK2019: unresolved external symbol __imp__al_load_ttf_font referenced in function "int __cdecl _mangled_main(int,char * * const)" (?_mangled_main@@YAHHQAPAD@Z)
1>sad.obj : error LNK2019: unresolved external symbol __imp__al_install_keyboard referenced in function "int __cdecl _mangled_main(int,char * * const)" (?_mangled_main@@YAHHQAPAD@Z)
1>sad.obj : error LNK2019: unresolved external symbol __imp__al_create_display referenced in function "int __cdecl _mangled_main(int,char * * const)" (?_mangled_main@@YAHHQAPAD@Z)
1>sad.obj : error LNK2019: unresolved external symbol __imp__al_init_font_addon referenced in function "int __cdecl _mangled_main(int,char * * const)" (?_mangled_main@@YAHHQAPAD@Z)
1>sad.obj : error LNK2019: unresolved external symbol __imp__al_install_system referenced in function "int __cdecl _mangled_main(int,char * * const)" (?_mangled_main@@YAHHQAPAD@Z)
1>sad.obj : error LNK2019: unresolved external symbol __imp___WinMain referenced in function _WinMain@16
1>***Documents\Visual Studio 2008\Projects\allegro 5\Debug\allegro 5.exe : fatal error LNK1120: 14 unresolved externals
1>Build log was saved at "****Documents\Visual Studio 2008\Projects\allegro 5\allegro 5\Debug\BuildLog.htm"
1>allegro 5 - 15 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

So it looks like I the library is not linked.

EDIT: btw, I am trying to compile the first tutorial from wiki.

Trent Gamblin

Did you include all the header files? Can you post the full source code as you have it and/or link to the exact article on the wiki you're following?

Malinus
#SelectExpand
1// hello1.c 2// An introduction to keyboard input and text output 3 4#include <allegro5/allegro5.h> 5#include <allegro5/allegro_font.h> 6#include <allegro5/allegro_ttf.h> 7#include <stdio.h> 8 9struct Data { 10 ALLEGRO_FONT *f1, *f2; 11 ALLEGRO_DISPLAY *display; 12 ALLEGRO_EVENT_QUEUE *queue; 13 14 ALLEGRO_COLOR bright_green; 15} data; 16 17const char *font_file = "times.ttf"; 18 19 20int main(int argc, char *argv[]) { 21 // Initialize Allegro 5 and the font routines 22 al_init(); 23 al_init_font_addon(); 24 25 // Create a window to display things on: 640x480 pixels 26 data.display = al_create_display(640, 480); 27 if(!data.display) { 28 printf("Error creating display.\n"); 29 return 1; 30 } 31 32 33 // Install the keyboard handler 34 if(!al_install_keyboard()) { 35 printf("Error installing keyboard.\n"); 36 return 1; 37 } 38 39 40 // Load a font 41 data.f1 = al_load_ttf_font(font_file, 48, 0); 42 data.f2 = al_load_ttf_font(font_file, -48, 0); 43 if(!data.f1 || !data.f2) { 44 printf("Error loading \"%s\".\n", font_file); 45 return 1; 46 } 47 48 // Make and set a color to draw with 49 data.bright_green = al_map_rgba_f(0.5, 1.0, 0.5, 1.0); 50 al_set_blender(ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, data.bright_green); 51 52 // Draw a message to the backbuffer in the fonts we just loaded using the color we just set 53 al_draw_text(data.f1, 10, 10, -1, "Allegro 5 Rocks!"); 54 al_draw_text(data.f2, 10, 60, -1, "Allegro 5 Rocks!"); 55 56 // Make the backbuffer visible 57 al_flip_display(); 58 59 // Start the event queue to handle keyboard input 60 data.queue = al_create_event_queue(); 61 al_register_event_source(data.queue, (ALLEGRO_EVENT_SOURCE*)al_get_keyboard_event_source()); 62 63 64 // Wait until the user presses escape 65 ALLEGRO_EVENT event; 66 while(1) { 67 // Block until an event enters the queue 68 al_wait_for_event(data.queue, &event); 69 70 // If the key was escape, then break out of the loop 71 if(event.type == ALLEGRO_EVENT_KEY_DOWN && event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) break; 72 } 73 74 75 return 0; 76} 77END_OF_MAIN()

From a.wiki.cc

Trent Gamblin

Ok, I see. Here's what you have to do:

1) put '#define ALLEGRO_STATICLINK 1' before you include allegro headers.
You need this when you're linking against static allegro librarie.

2) Add these libraries to your Linker Input:
kernel32.lib user32.lib gdi32.lib comdlg32.lib ole32.lib psapi.lib dinput8.lib d3d9.lib dxguid.lib winmm.lib opengl32.lib

Now it should work, but you have to remember it needs times.ttf in the right directory.

Malinus

Thank you Trent, it works now.

Trent said:

#define ALLEGRO_STATICLINK 1

Doh, of course. Didn´t think of the fact that the binary only comes with the static version.

Trent said:

Add these libraries to your Linker Input:
kernel32.lib user32.lib gdi32.lib comdlg32.lib ole32.lib psapi.lib dinput8.lib d3d9.lib dxguid.lib winmm.lib opengl32.lib

And how is this logical? These library´s don´t even come with the bin.

EDIT: If anyone else get the same problem, remember to add all the allegro librarys to the command line also.

Trent Gamblin

Most of them are part of windows, you don't need to download them. The only exceptions are d3d9.lib and dxguid.lib, which are part of directx, which does not come with the binaries. Just download the latest version from MS.

[edit]
DirectX sdk that is...

Thread #602418. Printed from Allegro.cc