感谢支持
我们一直在努力

Ubuntu下Code::Blocks环境中Allegro5的安装配置

我的系统是LUbuntu 11.04。

1. 安装code::blocks

2. 安装allegro5的依赖包,包括

libgl1-mesa-dev
libglu1-mesa-dev
cmake
build-essential
make

3.下载allegro5源代码

官网 http://alleg.sourceforge.net/

4.解压、编译、安装

$ cd allegro5
$ mkdir build
$ cd build
$ cmake ..
# or run cmakegui ..
$ make
$ sudo make install

此时用gcc编译文件test.c的命令为

gcc testal.c -o test -lallegro

或者

gcc test.c -o test $(pkg-config –libs allegro-5.0 allegro_image-5.0)

更多相关信息可以查看下载的源码包中README_pkgconfig.txt文件

5.配置code::blocks

pkg-config –list-all | grep allegro

查看allegro5库文件

pkg-config –cflags –libs allegro-5.0

查看头文件

在code::blocks中

setting->compiler and debugger settings ->linker settings

点击add,选/usr/local/lib下所有的liballegro开头的文件,

setting->compiler and debugger settings ->search directories

点add,选/usr/local/include

确定后在code::blocks中建console项目,添加源代码

  1. #include <stdio.h> 
  2. #include <allegro5/allegro.h> 
  3.  
  4. int main(int argc, char **argv) 
  5.     ALLEGRO_DISPLAY *display = NULL
  6.  
  7.    if(!al_init()) { 
  8.       fprintf(stderr, “failed to initialize allegro!\n”); 
  9.       return -1; 
  10.    } 
  11.  
  12.    display = al_create_display(640, 480); 
  13.    if(!display) { 
  14.       fprintf(stderr, “failed to create display!\n”); 
  15.       return -1; 
  16.    } 
  17.  
  18.    al_clear_to_color(al_map_rgb(0,0,0)); 
  19.    al_flip_display(); 
  20.    al_rest(10.0); 
  21.    al_destroy_display(display); 
  22.    return 0; 

编译、运行即可。

游戏编写完成后如果需要隐藏console窗口,按照下面的设置即可。

Hiding the console window with Code::Blocks

When you create a “New Project”, Code::Blocks, by default set it as a console project, that means that automatically will link a console to your project. This is very good because the console is great for debbuging, but once you’re ready to release your game/application you don’t need it anymore, so here are the simple steps to build your software without the console.

alt textTo get this menu, press the “project option” button, then press the “Build targets” tab and inside of the “Selected build target options” make sure that the “Type” option is set to “GUI application” instead of “Console application”. As you can see in the “build targets” section there is only the release mode, that’s because I never use the debug mode, but you should select to which type of build you want to hide the console.

Normally a debug mode should always have a console, while a release mode shouldn’t, but it’s not a rule.

赞(0) 打赏
转载请注明出处:服务器评测 » Ubuntu下Code::Blocks环境中Allegro5的安装配置
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏