Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » struggling with initialisation using CMake on arch

Credits go to Edgar Reynaldo for helping out!
This thread is locked; no one can reply to it. rss feed Print
struggling with initialisation using CMake on arch
Joshua Cassel
Member #17,061
March 2019

I've been trying all day to get allegro to work, ran into a few problems but it was mostly ok
but now i have a another one which ive managed to indentify but cant solve

I'm using the gcc compiler but i get the same problem with make and g++ aswell

To put it simply the package on the AUR conflicts with the one from github. I'm aware that the header version is 5.2.6 but the library is 5.2.4.1, and im pretty sure this is whats causing al_init to return false. However when i remove the aur package, nothing works at all. even after reinstalling with cmake

theres also something to do with pkg-config because 'pkg-config --list-all | grep allegro' returns a bunch of packages with the AUR package isntalled, but nothing when i remove it. but i really dont understand what pkg-config is or what it does. installed allegro with 'yay -S allegro' if thats relevant

Anyway, I cant find a solution anywhere, so thats why im here. Perhaps someone can help?

thanks for reading. be really nice if you could help me

also, unimportant, but it would be wonderful if someone could show me how to compile without having to add 'pkg-config blahblahblah...' after gcc

$gcc main.cpp -o main `pkg-config --libs allegro-5 allegro_font-5 allegro_ttf-5 allegro_main-5 allegro_primitives-5 allegro_color-5 allegro_image-5 allegro_dialog-5`

#SelectExpand
1main.cpp: In function 'int main()': 2main.cpp:18:93: warning: passing NULL to non-pointer argument 6 of 'int al_show_native_message_box(ALLEGRO_DISPLAY*, const char*, const char*, const char*, const char*, int)' [-Wconversion-null] 3 al_show_native_message_box(NULL, NULL, NULL, "failed to initialize allegro!", NULL, NULL); 4 ^ 5main.cpp:26:93: warning: passing NULL to non-pointer argument 6 of 'int al_show_native_message_box(ALLEGRO_DISPLAY*, const char*, const char*, const char*, const char*, int)' [-Wconversion-null] 6 al_show_native_message_box(NULL, NULL, NULL, "failed to initialize display!", NULL, NULL); 7 ^

$./main

#SelectExpand
1Library version: 5.2.4.1 2Header version: 5.2.6 (GIT) 3 4(process:6913): Gtk-WARNING **: 17:43:46.620: Locale not supported by C library. 5 Using the fallback 'C' locale. 6 7(main:6913): Gtk-WARNING **: 17:43:46.630: Unable to locate theme engine in module_path: "adwaita", 8Segmentation fault (core dumped)

edit:
just to confirm, after removing the package 'yay -R allegro', compiling using the same command as above, returns

#SelectExpand
1Package allegro-5 was not found in the pkg-config search path. 2Perhaps you should add the directory containing `allegro-5.pc' 3to the PKG_CONFIG_PATH environment variable 4Package 'allegro-5', required by 'virtual:world', not found 5Package 'allegro_font-5', required by 'virtual:world', not found 6Package 'allegro_ttf-5', required by 'virtual:world', not found 7Package 'allegro_main-5', required by 'virtual:world', not found 8Package 'allegro_primitives-5', required by 'virtual:world', not found 9Package 'allegro_color-5', required by 'virtual:world', not found 10Package 'allegro_image-5', required by 'virtual:world', not found 11Package 'allegro_dialog-5', required by 'virtual:world', not found 12main.cpp: In function 'int main()': 13main.cpp:18:93: warning: passing NULL to non-pointer argument 6 of 'int al_show_native_message_box(ALLEGRO_DISPLAY*, const char*, const char*, const char*, const char*, int)' [-Wconversion-null] 14 al_show_native_message_box(NULL, NULL, NULL, "failed to initialize allegro!", NULL, NULL); 15 ^ 16main.cpp:26:93: warning: passing NULL to non-pointer argument 6 of 'int al_show_native_message_box(ALLEGRO_DISPLAY*, const char*, const char*, const char*, const char*, int)' [-Wconversion-null] 17 al_show_native_message_box(NULL, NULL, NULL, "failed to initialize display!", NULL, NULL); 18 ^ 19/usr/bin/ld: /tmp/ccunZ0zw.o: in function `main': 20main.cpp:(.text+0x9): undefined reference to `al_get_allegro_version' 21/usr/bin/ld: main.cpp:(.text+0x92): undefined reference to `al_install_system' 22/usr/bin/ld: main.cpp:(.text+0xc0): undefined reference to `al_show_native_message_box' 23/usr/bin/ld: main.cpp:(.text+0xcf): undefined reference to `al_create_display' 24/usr/bin/ld: main.cpp:(.text+0x101): undefined reference to `al_show_native_message_box' 25/usr/bin/ld: main.cpp:(.text+0x114): undefined reference to `al_destroy_display' 26collect2: error: ld returned 1 exit status

after this, i ran... (in ~/build/)

#SelectExpand
1cmake ~/allegro5/ 2make -j12 3sudo make -j12 install

with no errors!

but compiling still fails :/

edit2:

ran

#SelectExpand
1PKG_CONFIG_PATH=$PKG_CONFIG_PATH:~/build/lib/pkgconfig

still nothing tho

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Okay, never used arch linux before but I can try to help.

Since you used 'yay -S allegro' I assume you have the dependecies installed.

You can build allegro yourself rather easily on linux once all the dependent packages are installed.

Install GIT and CMake.

Clone allegro from git. See here : https://liballeg.org/git.html

Once you have allegro cloned, build using cmake-gui or ccmake. Make sure to enable the WANT_MONOLITH option so you don't have to link to 10 different libraries.

After that, you can use pkg-config or link directly to the monolith library. By default, allegro installs to /usr/local .

Joshua Cassel
Member #17,061
March 2019

Thank you so much, I didnt realise that i needed to use ccmake and not cmake.
however, im not sure if im doing the last step correctly

I added the pkgconfig folder in usr/local to pkgconfig using 'CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig' but there are still no files named allegro in 'pkg-config --list-all' and i still get these errors when compiling.
edit: forgot to add errors

#SelectExpand
1main.cpp: In function 'int main()': 2main.cpp:18:93: warning: passing NULL to non-pointer argument 6 of 'int al_show_native_message_box(ALLEGRO_DISPLAY*, const char*, const char*, const char*, const char*, int)' [-Wconversion-null] 3 al_show_native_message_box(NULL, NULL, NULL, "failed to initialize allegro!", NULL, NULL); 4 ^ 5main.cpp:26:93: warning: passing NULL to non-pointer argument 6 of 'int al_show_native_message_box(ALLEGRO_DISPLAY*, const char*, const char*, const char*, const char*, int)' [-Wconversion-null] 6 al_show_native_message_box(NULL, NULL, NULL, "failed to initialize display!", NULL, NULL); 7 ^ 8/usr/bin/ld: /tmp/ccVjHEH4.o: in function `main': 9main.cpp:(.text+0x9): undefined reference to `al_get_allegro_version' 10/usr/bin/ld: main.cpp:(.text+0x92): undefined reference to `al_install_system' 11/usr/bin/ld: main.cpp:(.text+0xc0): undefined reference to `al_show_native_message_box' 12/usr/bin/ld: main.cpp:(.text+0xcf): undefined reference to `al_create_display' 13/usr/bin/ld: main.cpp:(.text+0x101): undefined reference to `al_show_native_message_box' 14/usr/bin/ld: main.cpp:(.text+0x114): undefined reference to `al_destroy_display' 15collect2: error: ld returned 1 exit status 16

I'm fairly sure i did, however, use ccmake correctly

edit2:
so i just need to link to the monolith library, right?
how do i do that?

edit3:
btw i used 'ccmake -DCMAKE_INSTALL_PREFIX=/usr ~/allegro5/' and followed the wiki's instructions on how to use it. making sure i enabled WANT_MONOLITH

edit4:
realised that in order to add the libraries, i need to add usr/local/lib and /usr/local/include to pkg-config

now, the allegro libs can be found in pkg-config, along with monolith
only problem now, is that the when compiling with

$gcc main.cpp -o main `pkg-config --libs allegro_monolith-5`

i get the error '/usr/bin/ld: cannot find -lallegro_monolith'

edit6:

also compiling with the command i used at the beginning works just fine, however i now get the error while running the compiled program: 'error while loading shared libraries: liballegro_ttf.so.5.2: cannot open shared object file: No such file
or directory'

edit7:
finally working :D
not a perfect setup, but i can now run ./main using 'LD_LIBRARY_PATH="/usr/local/lib" ./
main'

smh AUR update your packages

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Well, looks like you got it sorted. Can be quite confusing the first time.

Allegro's .pc files will be installed the same place you specified CMAKE_INSTALL_PREFIX, usually in their own pkgconfig folder.

As you found out, you can set PKG_CONFIG_PATH and LD_LIBRARY_PATH to get everything building and running.

Congrats on figuring it out. ;)

Go to: