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

