未在此范围内声明

未在此范围内声明

伙计们,我正在尝试在Ubuntu 11.04上安装allegro 5库。我遵循的教程是is
现在,在第一次尝试安装库时出现了一些错误,但是我可以克服它们并正确安装库。问题是当我尝试运行示例代码时

#include <allegro5/allegro.h>

int main(int argc, char *argv[])

{
allegro_init();

install_keyboard();

set_gfx_mode(GFX_AUTODETECT, 640,480,0,0);

readkey();

return 0;
}

END_OF_MAIN()

我收到类似的错误
ajinkya@ajinkya-8I945GZME-RH:~/random$ g++ example.cpp -o example -lalleg
example.cpp: In function ‘int main(int, char**)’:
example.cpp:7:15: error: ‘allegro_init’ was not declared in this scope
example.cpp:9:19: error: ‘install_keyboard’ was not declared in this scope
example.cpp:11:15: error: ‘GFX_AUTODETECT’ was not declared in this scope
example.cpp:11:42: error: ‘set_gfx_mode’ was not declared in this scope
example.cpp:13:10: error: ‘readkey’ was not declared in this scope
example.cpp: At global scope:
example.cpp:18:13: error: expected constructor, destructor, or type conversion at end   of input

我所有的主头文件都在/usr/include/allegro5中。

最佳答案

您是否检查了这些方法是否确实存在于头文件中?

似乎您使用的是Allegro 4 API而不是Allegro 5:
http://wiki.allegro.cc/index.php?title=Allegro_5_Tutorial/Displays

关于c++ - 未在此范围内声明“allegro_init()”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12055200/

10-09 00:09