I created a simple program that just draws a black square on a blue background to make sure everything works and is installed correctly:
// g++ -I "C:\msys64\mingw64\include\" test.cpp -o test.exe -g -lallegro -lallegro_primitives
#include <allegro5/allegro5.h>
#include <allegro5/allegro_primitives.h>
#include <iostream>
int main(int argc, char* argv[])
{
al_init();
ALLEGRO_DISPLAY* d = al_create_display(256, 256);
if (d == NULL)
std::cout << "Error in initializing display" << std::endl;
al_clear_to_color(al_map_rgb(0, 0, 255));
al_draw_filled_rectangle(64, 64, 192, 192, al_map_rgb(0, 0, 0));
al_flip_display();
al_rest(30);
al_destroy_display(d);
al_uninstall_system();
return 0;
}
...but when I try to run it with gdb .\test.exe
it returns this error:
Thread 1 received signal SIGSEGV, Segmentation fault.
al_lock_mutex (mutex=0x0) at C:/dev/allegro_winpkg/universal/allegro/src/threads.c:325
warning: 325 C:/dev/allegro_winpkg/universal/allegro/src/threads.c: No such file or directory
Here's the full stack trace:
#0 al_lock_mutex (mutex=0x0) at C:/dev/allegro_winpkg/universal/allegro/src/threads.c:325
#1 0x00007ffc351282bc in get_display_local_data (display=display@entry=0x616fa0)
at C:/dev/allegro_winpkg/universal/allegro/addons/primitives/prim_directx.cpp:138
#2 0x00007ffc35129a4b in draw_prim_raw (target=0x617280, texture=0x0, vtx=0x5ffd90, decl=0x0, indices=0x0, num_vtx=4,
type=5) at C:/dev/allegro_winpkg/universal/allegro/addons/primitives/prim_directx.cpp:500
#3 0x00007ffc3512a011 in _al_draw_prim_directx (target=target@entry=0x617280, texture=texture@entry=0x0,
vtxs=vtxs@entry=0x5ffd90, decl=decl@entry=0x0, start=<optimized out>, start@entry=0, end=<optimized out>,
end@entry=4, type=<optimized out>, type@entry=5)
at C:/dev/allegro_winpkg/universal/allegro/addons/primitives/prim_directx.cpp:656
#4 0x00007ffc3512e048 in al_draw_prim (vtxs=0x5ffd90, decl=0x0, texture=0x0, start=0, end=4, type=5)
at C:/dev/allegro_winpkg/universal/allegro/addons/primitives/primitives.c:104
#5 0x00007ffc35122784 in al_draw_filled_rectangle (x1=<optimized out>, y1=0, x2=<optimized out>, y2=0, color=...)
at C:/dev/allegro_winpkg/universal/allegro/addons/primitives/high_primitives.c:422
#6 0x00007ff7a78f1553 in main (argc=1, argv=0xf61b60) at test.cpp:16
I'm guessing there's some sort of step I missed in the setup process of mingw, but I don't know how to fix it. Anyone have any answers?
On my Linux system, your program works fine, but for Windows you might need to call (as said in comment):
al_init_primitives_addon();
before you can use a function such as al_draw_filled_rectangle
.