Allegro on iOS
Space cpp

Hello, Im having difficulties getting allegro to work on iOS.

At first I tried following the instructions included in README_iphone, but running cmake gave me lots of warnings about libraries not being installed, even though homebrew says they are.

So, I gave a try to the pre-built project. It compiled and generated an .a file.
Then I created a new xcode project using the single view application template with objective-c, and set the directories for the allegro headers and the library file.
I made a simple c++ function and called it inside ViewController/ViewDidLoad and it works fine.
Now for the allegro part, adding any allegro function call like al_init results in the following compiler error:

1Undefined symbols for architecture x86_64: 2 3 "__al_mangled_main", referenced from: 4 5 _user_main in libAllegro5_iOS.a(iphone_main.o) 6 7ld: symbol(s) not found for architecture x86_64 8 9clang: error: linker command failed with exit code 1 (use -v to see invocation)

How to proceed?


For various reasons Allegro needs to hijack your main. This can be handled transparently by the main addon, but for whatever reason it appears not to be working. Whenever this is an issue, you can always do the following:

#include <allegro5/allegro.h>

int real_main(int argc, char** argv)

int main(int argc, char** argv)
   return al_run_main(argc, argv, real_main);


Space cpp said:

but running cmake gave me lots of warnings about libraries not being installed, even though homebrew says they are.

This is because homebrew installs things that are compiled for your MacOS/OSX, but not for iOS. Generally that means having to compile the dependencies yourself, and we also provide somewhat outdated pre-compiled versions here:

Space cpp

After doing exactly like your code the project now compiles :)

Ok, I started writing a small program to see if everything is working fine. After a few minutes I ran in some compiler errors again.
My now look like this:

1#define ALLEGRO_NO_MAGIC_MAIN 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_primitives.h> 4#include <allegro5/allegro_image.h> 5#include <allegro5/allegro_native_dialog.h> 6#include <allegro5/allegro_font.h> 7#include <allegro5/allegro_ttf.h> 8#include <allegro5/allegro_audio.h> 9#include <allegro5/allegro_acodec.h> 10#include <allegro5/allegro_color.h> 11#include "stdio.h" 12 13 14ALLEGRO_DISPLAY *display = NULL; 15ALLEGRO_EVENT_QUEUE *event_queue = NULL; 16ALLEGRO_TIMER *timer = NULL; 17ALLEGRO_EVENT ev; 18ALLEGRO_TRANSFORM transform; 19 20const float FPS = 60; 21 22 23int real_main(int argc, char **argv) 24{ 25 26 // init 27 if (!al_init() ) printf("al_init Failed!\n"); 28 29 //if (!al_init_image_addon() ) { fprintf(stderr, "Failed to initialize al_init_image_addon!\n"); } 30 if (!al_init_primitives_addon() ) { printf("al_init_primitives_addon Failed!\n"); } 31 timer = al_create_timer(1.0 / FPS); if (!timer) { fprintf(stderr, "failed to create timer!\n"); } 32 al_init_font_addon(); 33 //if (!al_init_ttf_addon() ) { fprintf(stderr, "failed to initialize the ttf addon!\n"); } 34 //if (!al_init_acodec_addon() ) { fprintf(stderr, "failed to initialize audio codecs!\n"); } 35 //if (!al_reserve_samples(8) ) { fprintf(stderr, "failed to reserve samples!\n"); } 36 37 display = al_create_display(1024, 768); 38 if (!display) 39 { 40 printf("al_create_display Failed!\n"); 41 } 42 43 al_clear_to_color( al_map_rgb(0,0,0) ); 44 al_flip_display(); 45 46 47 event_queue = al_create_event_queue(); 48 49 al_register_event_source(event_queue, al_get_display_event_source(display)); 50 al_register_event_source(event_queue, al_get_timer_event_source(timer)); 51 52 53 // draw something 54 al_clear_to_color( al_map_rgb(0,128,255) ); 55 al_draw_filled_rectangle(0, 0, 100, 50, al_map_rgb(255,0,0) ); 56 al_draw_filled_rectangle(200, 200, 300, 250, al_map_rgb(0,255,0) ); 57 al_flip_display(); 58 59 60 al_rest(5); 61 62 63 // clean 64 al_destroy_display(display); 65 al_destroy_timer(timer); 66 al_destroy_event_queue(event_queue); 67 68 return 0; 69 70} 71 72 73 74int main(int argc, char * argv[]) 75{ 76 77 /* 78 @autoreleasepool 79 { 80 return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 81 }*/ 82 83 return al_run_main(argc, argv, real_main); 84 85}

See the 4 commented lines at the init section: These calls are producing a long list of compiler errors just like the one on the first post "Undefined symbols for architecture x86_64: blah blah blah referenced from:"


It probably makes sense for TTF addon to be missing, as you probably don't have the correct freetype, but strange that you're missing the other ones. Are you using the... pre-made XCode project? I'm not super familiar with it.

Space cpp

I used the project included in misc/Allegro5_iOS to generate the library file.

Is it necessary to manually compile/install the dependencies in order for that project to work correctly?

I'm trying the cmake method again. Downloaded the 3 pre-compiled dependencies you mentioned and put the content inside "deps" folder, but it doesn't seen cmake is making any use of the content there at all.
I run the following command:

cmake -DCMAKE_TOOLCHAIN_FILE=allegro- -G Xcode \ -DIOS_PLATFORM="iphoneos" -DWANT_EXAMPLES=off -DWANT_DEMO=off -DWANT_TESTS=off -DWANT_PHYSFS=no allegro-

Then the terminal shows:

1-- Adding /Users/rodrigo/allegro- to CMAKE_PREFIX_PATH 2-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) 3-- Performing Test ALLEGRO_HAVE_PROCFS_ARGCV 4-- Performing Test ALLEGRO_HAVE_PROCFS_ARGCV - Failed 5-- Performing Test ALLEGRO_HAVE_SV_PROCFS_H 6-- Performing Test ALLEGRO_HAVE_SV_PROCFS_H - Failed 7-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) 8-- Could NOT find OPENSL (missing: OPENSL_INCLUDE_DIR OPENSL_LIBRARY) 9-- Performing Test FLAC_COMPILES 10-- Performing Test FLAC_COMPILES - Failed 11WARNING: libFLAC not found or compile test failed, disabling support. 12-- Could NOT find DUMB (missing: DUMB_INCLUDE_DIR DUMB_LIBRARY) 13WARNING: libdumb >= 2.0 or <= 0.9.3 not found or compile test failed, disabling support. See <> for 2.0 or <> for 0.9.3. 14-- Performing Test VORBIS_COMPILES 15-- Performing Test VORBIS_COMPILES - Failed 16WARNING: libvorbis not found or compile test failed, disabling support. 17-- Performing Test OPUS_COMPILES 18-- Performing Test OPUS_COMPILES - Failed 19WARNING: libopus not found or compile test failed, disabling support. 20-- Performing Test TTF_COMPILES 21-- Performing Test TTF_COMPILES - Failed 22-- Performing Test TTF_COMPILES_WITH_EXTRA_DEPS 23-- Performing Test TTF_COMPILES_WITH_EXTRA_DEPS - Failed 24CMake Warning at addons/CMakeLists.txt:126 (message): 25 FreeType doesn't compile. Disabling support. 26 27 28-- Could NOT find LATEX (missing: LATEX_COMPILER) 29-- Configuring done 30-- Generating done 31-- Build files have been written to: /Users/rodrigo

Any ideas?


Bumping the thread to prevent the lock. I'll take a look this weekend at what the status of this is.

EDIT: So I tried this, and indeed, aside from physfs, it didn't appear that the deps worked. The errors looked like versions mismatches, so perhaps if the dependencies are rebuilt, it'd work fine. What I'll do next is follow directions outlined here: (with updated paths) and see if I can get it working.

Thread #617172. Printed from