Problem with Allegro image call by Mac C terminal

Asked

Viewed 253 times

0

Guys have a problem here, I’m playing a game using the Allegro, I am compiling by the terminal and ta ok, there is only one however, when I load an image of the fault when loading the image, the problem is not the code, I have tried to run code that ran on other computers, but on mine does not run. The interesting thing is that I run the code through the terminal using . /executavel.exe it runs normally as it should, the image appears and everything 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 clicks on the error executable when loading the image. I can not say why 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 solve knowing that it is not a matter of wrong code since it compiles normally straight 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 executable folder

Yes when I compile I call -lallegro_image

I was told that it could be permission problem, however I do not know how to solve it, I am Noob in OSX

  • What is your compiler and version of Allegro. If you don’t know, send the tutorial you used to install

  • @krystalgamer, my compiler is gcc and Allegro is 5.0

1 answer

0


First

Are you sure that the allegro is installed?

Even if you have go to your directory toolchain or of IDE(must be the Xcode) and see if inside the folder include has a folder there called allegro5. If you can go on

Solution

Go to LIB_DIR that your Inker go and find something started by liballegro*, find yourself just call -lallegro* (NOTE: The asterisk is to be replaced).

For example in my version of Allegro I don’t need to indicate every library I use (image, sound, source.) it’s all in one call liballegro_monolith.dll.a(Windows), and so 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 down on the terminal ld --verbose | grep SEARCH

Will list all possible reports.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.