且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用allegro 5和g ++编译C ++代码

更新时间:2022-01-21 02:14:52

从SVN在您的系统上安装 allegro5 。您应该知道的一件事是,这个构建不附带 allegro-config 。如果您在系统上安装了它,则表示您之前已安装了 allegro4

So you successfully installed allegro5 on your system from the SVN. One thing you should know is that this build doesn't come with allegro-config. If you have it on your system it means you have previously installed allegro4.

allegro5带来了许多更改,包括不同的初始化过程,库和函数名称。

allegro5 brings many changes, including different initialization procedures, library and function names.

这是一个新版本的hello world应用程序:

Here's a hello world application for new version:

#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;
}

注意到另一个包括与以前版本的allegro不同的目录和库名称:

Notice how the command to compile this application refers to another include directory and library names, which are different from the previous version of allegro:

g++ hello.cpp -o hello -I/usr/include/allegro5 -L/usr/lib -lallegro