Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Install Allegro 5.2.4.1 on Win10

This thread is locked; no one can reply to it. rss feed Print
Install Allegro 5.2.4.1 on Win10
pairslipper
Member #16,830
March 2018

I'm new to both Allegro 5 and C programming (can write simple programs, but doesn't have much experience in things such as build, make, compile, etc.). Currently I didn't meet too much difficulties on both installation and programming on macOS. However, when turning to windows platform (Win10), I still cannot run a simple program after one day on search and tries.

I've downloaded the binary-build version (allegro-x86_64-w64-mingw32-gcc-7.2.0-posix-seh, both dynamic and static version), and set their /bin path to system PATH variable.

First I tried to run program on CLion, with toolchain:
mingw64 7.2.0 (x86_64, posix, seh)
CMake 3.9.6 (Bundled in CLion)
GNU gdb 8.0.1
(make and gcc are bundled in mingw64, but I can't see the version from CLion.)
/bin path of mingw64 is also added to system PATH variable.

This is the CMakeLists.txt for the project:

#SelectExpand
1cmake_minimum_required(VERSION 3.9) 2project(allegro5_test_c90 C) 3 4set(CMAKE_C_STANDARD 90) 5 6add_executable(allegro5_test_c90 main.c) 7 8INCLUDE_DIRECTORIES( C:/Allegro5/allegro-x86_64-w64-mingw32-gcc-7.2.0-posix-seh-static-5.2.4.1/allegro/include ) 9LINK_DIRECTORIES( C:/Allegro5/allegro-x86_64-w64-mingw32-gcc-7.2.0-posix-seh-static-5.2.4.1/allegro/lib ) 10 11file(GLOB LIBRARIES "C:/Allegro5/allegro-x86_64-w64-mingw32-gcc-7.2.0-posix-seh-static-5.2.4.1/allegro/lib/*.dll.a") 12message("LIBRARIES = ${LIBRARIES}") 13 14TARGET_LINK_LIBRARIES(allegro5_test_c90 ${LIBRARIES})

This is the code I tried to run from YouTube tutorial.

#SelectExpand
1#include <stdio.h> 2 3#include <allegro5/allegro.h> 4#include <allegro5/allegro_native_dialog.h> 5#include <allegro5/allegro_font.h> 6#include <allegro5/allegro_ttf.h> 7#include <allegro5/allegro_primitives.h> 8 9#define ScreenWidth 800 10#define ScreenHeight 600 11 12int main(int argc, char **argv){ 13 14 if(!al_init()){ 15 al_show_native_message_box(NULL, NULL, NULL, "Init failed!", NULL, ALLEGRO_MESSAGEBOX_WARN); 16 return -1; 17 } 18 19 ALLEGRO_DISPLAY *display = NULL; 20 al_set_new_display_flags(ALLEGRO_WINDOWED); 21 display = al_create_display(ScreenWidth, ScreenHeight); 22 23 al_set_window_position(display, 200, 100); 24 al_set_window_title(display, "Test Title"); 25 if(!display){ 26 al_show_native_message_box(display, "Sample Title", "Display Settings", "Failed on Display!", NULL, ALLEGRO_MESSAGEBOX_WARN); 27 return -1; 28 } 29 30 al_init_font_addon(); 31 al_init_ttf_addon(); 32 33 ALLEGRO_FONT *font = al_load_font("./../Font/Arial.ttf", 36, 0); 34 al_draw_text(font, al_map_rgb(44, 117, 255), ScreenWidth / 2, ScreenHeight / 2, ALLEGRO_ALIGN_CENTRE, "Hello!"); 35 36 al_flip_display(); 37 38 al_init_primitives_addon(); 39 ALLEGRO_COLOR electricBlue = al_map_rgb(44, 117, 255); 40 ALLEGRO_COLOR red = al_map_rgb(255, 0, 0); 41 ALLEGRO_COLOR green = al_map_rgb(0, 255, 0); 42 float points[8] = {0, 0, 400, 100, 50, 200, ScreenWidth, ScreenHeight}; 43 44 al_draw_filled_triangle(10, 10, 20, 10, 15, 50, red); 45 al_draw_rounded_rectangle(10, 10, 100, 100, 5, 5, green, 3); 46 al_draw_rectangle(400, 400, 450, 500, al_map_rgb(255, 98, 100), 9.0); 47 al_draw_circle(ScreenWidth/2, ScreenHeight/2, 10, al_map_rgb(255, 255, 0), 3.0); 48 al_draw_ellipse(ScreenWidth/2, ScreenHeight - 100, 10, 5, al_map_rgb(255, 0, 255), 4.0); 49 al_draw_arc(10, ScreenHeight - 100, 10, 0, 4.0, al_map_rgb(255, 0, 0), 2.0); 50 al_draw_line(100, 500, 300, 500, electricBlue, 6.0); 51 al_draw_pixel(500, 500, electricBlue); 52 al_draw_spline(points, electricBlue, 1.0); 53 al_flip_display(); 54 55 al_rest(10.0); 56 57 al_destroy_font(font); 58 al_destroy_display(display); 59 60 return 0; 61}

However it only turns out to be error message below:

Assertion failed!

Program: C:\Users\b9870\CLionProjects\allegro5_test_c90\cmake-build-debug\allegro5_test_c90.exe
File: C:/dev/allegro_winpkg/universal/allegro/src/misc/vector.c, Line 174

Expression: vec->_itemsize > 0

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Then, since there is only tutorial for Allegro on Code::Blocks and MSVS, I tried installing Code::Blocks and follow the instructions on this page:
https://wiki.allegro.cc/index.php?title=Windows,_Code::Blocks_and_Allegro_5
However, it doesn't work on both static and dynamic version.

On static version: (Compile error?)

gcc.exe -Wall -g -IC:\Allegro5\allegro-x86_64-w64-mingw32-gcc-7.2.0-posix-seh-static-5.2.4.1\allegro\include -c D:\Allegro_CB_test\allegro5_static_test\test.c -o obj\Debug\test.o
g++.exe -LC:\Allegro5\allegro-x86_64-w64-mingw32-gcc-7.2.0-posix-seh-static-5.2.4.1\allegro\lib -o bin\Debug\allegro5_static_test.exe obj\Debug\test.o  -static-libstdc++ -static-libgcc -lallegro_monolith-debug-static -ljpeg -ldumb -lFLAC -lfreetype -lvorbisfile -lvorbis -logg -lphysfs -lpng16 -lzlibstatic -ldsound -lgdiplus -luuid -lkernel32 -lwinmm -lpsapi -lopengl32 -lglu32 -luser32 -lcomdlg32 -lgdi32 -lshell32 -lole32 -ladvapi32 -lws2_32 -lshlwapi  
C:/Program Files/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ljpeg
C:/Program Files/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ldumb
C:/Program Files/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lFLAC
C:/Program Files/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lfreetype
C:/Program Files/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lvorbisfile
C:/Program Files/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lvorbis
C:/Program Files/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -logg
C:/Program Files/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lphysfs
C:/Program Files/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lpng16
C:/Program Files/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lzlibstatic
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 2 second(s))

On dynamic version: (Run error)

Assertion failed!

Program: D:\Allegro_CB_test\allegro5_static_test\bin\Debug\allegro5_static_test.exe
File: C:/dev/allegro_winpkg/universal/allegro/addons/font/text.c, Line 79

Expression: font

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

I have no idea about what caused these problems, and want to get some suggestions. I can go back to macOS, but still I prefer to do my work on the machine that uses Windows OS more.

In the worst case, I guess building the whole library on my machine is required, but currently I'm not clear about how to build the library from scratch after some Google search, and feeling like circling in the forest and get stuck....

(Update)
Also, I want to know how to search threads in this forum more efficiently. I want to find recent articles to see if there's any post with problem similar to mine's, but it doesn't provide efficient way to search for posts earlier.

Edgar Reynaldo
Member #8,592
May 2007
avatar

Hello pairslipper,

On our forums, you can use XHTML tags to mark up your post. Use <code>code goes here...</code> tags to post code, and <pre>preformatted text goes here...</pre> tags to post console logs. It will make your post much easier to read, and much easier for us to help you. You can edit your post with the little pen and paper icon at the top of your posts.

The 'font' assertion fails because your font failed to load.

The static compile errors are because you don't have the dependencies. Or maybe they are named differently in the official 'deps' package. I'm not sure.

The 'vec->item_size > 0' assertion may be coming from anywhere. To figure out why, you need to register an assert handler that divides by zero. This will allow you to catch the assert in your debugger. When the assertion fails, it will trigger the divide by zero, which gdb can catch. At that point, call 'backtrace' to see where you are in the function stack.

void AssertHandler(const char* expr , const char* file , int line, const char* func) {
   printf("Expression \"%s\" failed on line %d of file %s in function %s\n",
          expr , line , file , func);
   int i = 1/0;
}

al_register_assert_handler(AssertHandler);

pairslipper
Member #16,830
March 2018

I tried update the post by using tags you mentioned, but it doesn't look tidier.

As for problems on font, removing all lines related to fonts and text-drawing on CLion will cause runtime error, without any message shown on screen or console panel.

I'll try following these advise tonight. As previously mentioned, I don't have much experience on C/C++ programing, let me rest for a while...

(Update) I added the assert handler code and run debug on CLion. But the program terminated as usual and left the same message on console. Now I need to spend additional hours on how to use debugger...

Edgar Reynaldo
Member #8,592
May 2007
avatar

Neil Roy
Member #2,229
April 2002
avatar

Uninstall Windows 10, re-install Windows 7. Problem solved. ;) (sorry, couldn't help myself)

Edgar Reynaldo
Member #8,592
May 2007
avatar

Neil Roy
Member #2,229
April 2002
avatar

It's a joke Edgar, you missed it. Grow a sense of humour. ;)

Edgar Reynaldo
Member #8,592
May 2007
avatar

Neil Roy
Member #2,229
April 2002
avatar

The joke was bound to fail.

I should have known better than to expect any humour out of you. My bad.

Edgar Reynaldo
Member #8,592
May 2007
avatar

pairslipper
Member #16,830
March 2018

Now the code works on Code::Blocks with dynamic build (surely there are some dependency issues for the static build). The runtime error seems to be caused by failed font loading.

It's glad that I can start working on the windows machine. Still it doesn't work on CLion, but now I can deferred that until I have free time.

Edgar Reynaldo
Member #8,592
May 2007
avatar

pairslipper
Member #16,830
March 2018

CLion is an IDE for C/C++ programming. But it's commercial product and I'm using student trial now. Your question reminds me that it's better to change IDE on the macOS machine, because it's not free anymore after graduation...

Neil Roy
Member #2,229
April 2002
avatar

I recently compiled my Deluxe Pacman 2 game with the latest Allegro which I compiled myself. It was a static build and compile with zero problems. It uses bitmap fonts, truetype fonts, loads data from a zip using physfs, you name it.

The runtime error seems to be caused by failed font loading.

Seems? Do you check return values and report when a load fails?

In my own game I have the following Allegro 5 code for font loading...

   ALLEGRO_FONT *font_radio_space_bold = NULL;

   font_radio_space_bold = al_load_ttf_font("Fonts/Radio_Space_Bold.ttf", 12, 0);
   if(!font_radio_space_bold) {
      a5_error(AT, setting.screen, "Error loading Radio_Space_Bold.ttf.");
      shut_down();
      exit(1);
   }

In Code::Blocks, I use "allegro_monolith-static".

For my linked libs, I have (copy and pasted from my codeblocks project file). Maybe this will help...

<Linker>
   <Add option="-m32" />
   <Add option="-static" />
   <Add option="-static-libgcc" />
   <Add library="mingw32" />
   <Add library="dumb" />
   <Add library="FLAC" />
   <Add library="vorbisfile" />
   <Add library="vorbis" />
   <Add library="freetype" />
   <Add library="ogg" />
   <Add library="physfs" />
   <Add library="png16" />
   <Add library="zlibstatic" />
   <Add library="gdiplus" />
   <Add library="uuid" />
   <Add library="kernel32" />
   <Add library="winmm" />
   <Add library="psapi" />
   <Add library="opengl32" />
   <Add library="glu32" />
   <Add library="user32" />
   <Add library="comdlg32" />
   <Add library="gdi32" />
   <Add library="shell32" />
   <Add library="ole32" />
   <Add library="advapi32" />
   <Add library="ws2_32" />
   <Add library="shlwapi" />
   <Add library="dsound" />
   <Add library="jpeg" />
   <Add library="opusfile" />
   <Add library="opus" />
</Linker>

pairslipper
Member #16,830
March 2018

For static build, I followed the instructions in this page:
https://wiki.allegro.cc/index.php?title=Windows,_Code::Blocks_and_Allegro_5

And the error message appeared to be the things I posted in the first article. It seems that some of the libraries can't be found. I think supposedly they should be packed into the binary build.

Edgar Reynaldo
Member #8,592
May 2007
avatar

Go to: