c – allegro5 – 如何在Linux上运行?

我设置了Allegro 5,并且可以成功编译以下代码:

#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;
}

但运行后,它失败并显示错误消息:

Could not initailize allegro : No such file or directory.

我不知道出了什么问题.我的操作系统是Ubuntu,我用以下代码成功编译了代码:

gcc try.c -lallegro 

但无法运行它:

./a.out

解决方法:

Allegro需要配置文件以及可能的其他文件才能运行.从您的评论中,这可能就是为什么它不起作用.从自述文件:

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/.

看更多:

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

上一篇:使用scipy的quad例程将函数与奇点集成


下一篇:Allegro利用Skill语言实现通过焊盘获取对应的网络名的功能