Search code examples
c++gccallegroallegro5

C++ Executable not working from folder, but working from console on Mac


I have this strange problem with a game I'm making in c++ with Allegro.

There is a part of the game that uses some images from the source folder.

I compile it through gcc and create the executable file main, it works fine when I call ./main from the terminal... The games load every images and works just fine.

But if I open finder, navigate and double click on the same main it crashes because it doesn't success on loading the images from the source. The same thing happens if I try to open it from Instruments too.

The source code folder structure is:

project: | main //the executable is in the root of the project folder | /src //Where all the cpp and h files are stored | /obj //Where the .o files are stored | item.png //images are also in the root of the project folder

and the image loading function is the base function of Allegro

al_load_bitmap("item.png");

Solution

  • This is the expected behaviour on macOS. You need a bundle for this to work. It's in the official macOS faq:

    http://liballeg.org/stabledocs/en/build/macosx.html

    Ues a tool called fixbundle.