简体   繁体   中英

allegro5 - How to run on Linux?

I set up Allegro 5, and could compile the following code with success:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <allegro5/allegro.h>
void error(char *msg)
{
   fprintf(stderr,"%s : %s\n", msg, strerror(errno));
   exit(1);
}
int main(int argc, char **argv)
{
ALLEGRO_DISPLAY *display = NULL;

if(!al_init())
   error("Could not initailize allegro");

display = al_create_display(640, 480);
if(!display)
   error("fail to display");

al_clear_to_color(al_map_rgb(0,0,0));
al_flip_display();
al_rest(10.0);
al_destroy_display(display);
return 0;
}

But after running it, it failed with the error message:

Could not initailize allegro : No such file or directory.

I don't know what is wrong. My OS is Ubuntu, I'd compiled the code successfully with:

gcc try.c -lallegro 

But could not run it with:

./a.out

Allegro needs a configuration file and possibly other files to operate. From your comment, that is probably why it is not working. From the readme:

"

Normally the setup program and allegro.cfg will go in the same directory as the Allegro program they are controlling. This is fine for the end user, but it can be a pain for a programmer using Allegro because you may have several programs in different directories and want to use a single allegro.cfg for all of them. If this is the case you can set the environment variable ALLEGRO to the directory containing your allegro.cfg, and Allegro will look there if there is no allegro.cfg in the current directory.

...

Under Unix, BeOS and MacOS X, the config file routines also check for ~/allegro.cfg, ~/.allegrorc, /etc/allegro.cfg, and /etc/allegrorc, in that order, and the keyboard and language files can be stored in your home directory or in /etc/.

See more:

http://alleg.sourceforge.net/stabledocs/en/readme.html#configuration

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM