|
How to compile an Allegro 5 program? |
David Pavezka
Member #17,392
January 2020
|
Hi, I'm very very sorry, but I'm a novice in Allegro (and C programming in general), and I haven't found a good answer to my problem online, so I'll ask here, at a risk of coming off as a giant noob (that I probably am ): gcc hello.c -o hello.exe $(pkg-config allegro-5 allegro_font-5 --libs --cflags) does not work, and I'm not sure how to link the libraries using -l commands. I'm almost certain that I've configured the library correctly (following the guide). The command above produces: gcc: error: $(pkg-config: No such file or directory gcc: error: allegro-5: No such file or directory gcc: error: allegro_font-5: No such file or directory gcc: error: unrecognized command line option '--libs' gcc: error: unrecognized command line option '--cflags)' The command above, but without the dollar sign and stuff in parenthesis (gcc hello.c -o hello.exe) produces: c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x21): undefined reference to `al_install_system' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x26): undefined reference to `al_install_keyboard' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x34): undefined reference to `al_create_timer' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x40): undefined reference to `al_create_event_queue' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x5b): undefined reference to `al_create_display' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x67): undefined reference to `al_create_builtin_font' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x73): undefined reference to `al_get_keyboard_event_source' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x86): undefined reference to `al_register_event_source' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x95): undefined reference to `al_get_display_event_source' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0xa8): undefined reference to `al_register_event_source' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0xb7): undefined reference to `al_get_timer_event_source' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0xca): undefined reference to `al_register_event_source' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0xe1): undefined reference to `al_start_timer' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0xf8): undefined reference to `al_wait_for_event' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x13e): undefined reference to `al_is_event_queue_empty' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x166): undefined reference to `al_map_rgb' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x193): undefined reference to `al_clear_to_color' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x1ba): undefined reference to `al_map_rgb' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x211): undefined reference to `al_draw_text' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x216): undefined reference to `al_flip_display' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x232): undefined reference to `al_destroy_font' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x241): undefined reference to `al_destroy_display' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x250): undefined reference to `al_destroy_timer' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DAWIDP~1\AppData\Local\Temp\cceUBMFy.o:hello.c:(.text+0x25f): undefined reference to `al_destroy_event_queue' Any help would be appreciated . |
Edgar Reynaldo
Major Reynaldo
May 2007
|
You don't use pkg-config on Windows. Just link directly with the allegro libraries. Did you download binaries? Or did you build allegro yourself? Are you using the monolith? Or the addon libraries? You need to link to each one you use. They come in the 'lib' folder. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
David Pavezka
Member #17,392
January 2020
|
1. I downloaded this release from github: allegro-x86_64-w64-mingw32-gcc-8.2.1-posix-seh-static-5.2.5.1.zip I tried using, gcc hello.c -lallegro-static -lallegro_font-static -o hello.exe, but to no avail. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Okay. We'll get this sorted. 1) You're using 64 bit MinGW-W64 GCC 8.2 binaries. Do they match the compiler you're using? At a command prompt, enter 'gcc --version' with mingw\bin on your path. 2) The libraries are labeled properly. Just read the names. Either there will be a monolith or there will be addons or there will be both. 3) You need to link to each library you use. The monolith library is provided as a 'shortcut' to linking to every allegro addon library, including the main allegro library. Determine which you're using first, and then link to them. -lNAME where the file is named libNAME.a is the command line option you use to link. 4) You can link either dynamically (and depend on .dll files) or statically. Choose one. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
David Pavezka
Member #17,392
January 2020
|
1. My version of GCC is 8.2.0-5; I know it's not 8.2.1, but I hope it's close enough, since there's no 8.2.0 build and I know building the library myself may be tiresome. Also, I just now noticed that allegro builds are only 64 bit, but AFAIK MinGW is only offering GCC in 32bit format (I'm running Windows 10 64bit). Am I missing something? 2&3&4. The program uses only the allegro5.h and allegro_font.h. I'm pretty sure I want to compile statically (so no .dll, right?) so I tried using -lallegro-static -lallegro_font-static, but it's the same error. Same with -lallegro_monolith-static. So is the cause the difference in bits? Cause if so, since MinGW is only 32 bit (AFAIK) do I have to compile the library myself? Edit: See, this is why you shouldn't live under a rock, cause it turned out there is a 64 MinGW that I had no idea about. I'll check it out and report later. Also, I just found out that i686 means 32-bit, so... uh... yeah... |
Edgar Reynaldo
Major Reynaldo
May 2007
|
When you link statically, there is a whole list of other libraries you have to link with. They are attached. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
David Pavezka
Member #17,392
January 2020
|
Ok, at first it threw an error about missing libraries; I get those, and the same error occurs! I'll try using mingw-w64 now, maybe this'll help... |
Edgar Reynaldo
Major Reynaldo
May 2007
|
David Pavezka, You probably forgot to add the search directory for the linker. You need to pass the path to where the libraries are so it can find them. -L path\to\libs If it still isn't working, post the errors that you get. If it's long, use pastebin. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
bamccaig
Member #7,536
July 2006
|
No need to use a pastebin when posting large output on Allegro.cc. The Web is not IRC. Just post them here. It'll be fine. I doubt the output could be any larger than a megabyte or so. Of course, you could also put the output into a file and attach it. On a side note, I get the feeling that Edgar may be assuming a certain level of knowledge/experience that you may not meet. If you feel you don't understand the advice you're given that's OK. Just say so. There's also the old adage that if you teach a man to fish they'll eat for life. It's great to find out what you're missing, but it's even better to understand what's happening so you can figure it out for yourself next time. If you have any questions about why you need to do something ask. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
|