【发布时间】:2012-12-18 01:20:37
【问题描述】:
我设置了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;
}
但运行后,它失败了,错误信息:
无法初始化 allegro:没有这样的文件或目录。
我不知道出了什么问题。我的操作系统是 Ubuntu,我已经成功编译了代码:
gcc try.c -lallegro
但无法运行它:
./a.out
【问题讨论】:
-
我不知道 Allegro,但尝试安装 strace 并运行
strace ./a.out以查看它找不到的确切内容。 -
它显示:access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (没有这样的文件或目录) open("/home/tom/Exercise/c/game /allegro5.cfg", O_RDONLY) = -1 ENOENT (没有这样的文件或目录) open("/etc/allegro5rc", O_RDONLY) = -1 ENOENT (没有这样的文件或目录) open("/home/dreamloser/allegro5rc ", O_RDONLY) = -1 ENOENT(没有这样的文件或目录)
-
您应该使用
pkg-config而不是-lallegro。无论如何,编译 Allegro 的调试版本并查看 allegro.log。