我的系统是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项目,添加源代码
#include <stdio.h>
#include <allegro5/allegro.h>
int main(int argc, char **argv)
{
ALLEGRO_DISPLAY *display = NULL;
if(!al_init()) {
fprintf(stderr, "failed to initialize allegro!n");
return -1;
}
display = al_create_display(640, 480);
if(!display) {
fprintf(stderr, "failed to create display!n");
return -1;
}
al_clear_to_color(al_map_rgb(0,0,0));
al_flip_display();
al_rest(10.0);
al_destroy_display(display);
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.
声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。