Problem with Allegro image call by C terminal Mac

0

I have a problem here, I'm making a game using Allegro , I'm compiling the terminal and it's okay, there's only one, however, when I load an image of the failure while loading the image , the problem is not the code, I already tried to run code that ran on other computers, but in mine does not run. The most interesting thing is that if I run the code through the terminal using ./executavel.exe it runs normally as it should, the image appears and everything is quiet. Does anyone know how I can solve this? Leaving the doubt more explicit: The executable only runs when the execution is done by the terminal, when I give 2 executions of the error when loading the image. I can not tell you why of the error since when I do not load the image by clicking 2 times on the executable, it runs normally, which makes me think that the image is the problem. The question is, how to resolve knowing that it is not a wrong code issue since it normally compiles directly from the terminal?

Here is the code:

#include <stdio.h>

//puxa a biblioteca allegro
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_image.h>

//fixo de tamanho de tela
#define LAR 1280
#define ALT 720

int main(int argc, char *argv[]){
//inicialização da janela
ALLEGRO_DISPLAY *janela = NULL;

ALLEGRO_BITMAP *imagem = NULL;

//inicia allegro, caso erro da a msg
if(!al_init()) {
    fprintf(stderr, "failed to initialize allegro!\n");
    return -1;
}

al_get_standard_path(ALLEGRO_RESOURCES_PATH);

//cria a janela
janela = al_create_display(LAR, ALT);
if(!janela) {
    fprintf(stderr, "failed to create display!\n");
    return -1;
}

//inicia primitivos
//al_init_primitives_addon();

//inicia a extenção de imagens
if(!al_init_image_addon()){
    fprintf(stderr, "Falha ao carregar image addon");
}

//carrega imagem
imagem = al_load_bitmap("imagem.jpg");
if (!imagem){
    fprintf(stderr, "Falha ao carregar imagem!\n");
    return -1;
}

//preenche a tela com alguma cor
al_clear_to_color(al_map_rgb(0,0,0));

//desenha imagem
al_draw_bitmap(imagem, LAR/2 - (al_get_bitmap_width(imagem)/2),
               ALT/2 - (al_get_bitmap_height(imagem)/2), 0);

//atualiza a tela
al_flip_display();

//pausa a execução
al_rest(10.0);

//destroi imagem
al_destroy_bitmap(imagem);

//destroi variavel janela
al_destroy_display(janela);

return 0;
}

My Mac is Yosemite 10.10.5

F.A.Q

Yes the image has the same name that I refer to in the code

Yes it is in the same folder as the executable

Yes when I compile I call -lallegro_image

I was told that it might be a permission problem, but I do not know how to solve this, I'm noob on OSX

    
asked by anonymous 03.09.2015 / 04:28

1 answer

0

First

Are you sure allegro is installed?

Even if you go to the directory of your toolchain or IDE ( must be Xcode ) and verify that within the include folder there is a folder named allegro5 . If so you can continue

Solution

Go to the LIB_DIR that your linker will look for and see if something is found with liballegro* , if it finds, just call -lallegro* ( NOTE: The asterisk is to be replaced ).

For example, in my version of allegro I do not need to indicate every library I use (image, sound, font ..) is all in a liballegro_monolith.dll.a (Windows) call, so it's just compile with -lallegro_monolith . You can try and see if it works too.

How do I know which directories my compiler / linker accesses

Just write this in the terminal ld --verbose | grep SEARCH

It will list all possible directories.

    
03.09.2015 / 21:36