使用 allegro 5 和 g++ 编译 C++ 代码 [英] Compiling C++ code with allegro 5 and g++

查看:36
本文介绍了使用 allegro 5 和 g++ 编译 C++ 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了使用 allegro 5 编译代码,我需要向 g++ 添加哪些标志?我试过了

What flags do I need to add to g++ in order to compile code using allegro 5? I tried

g++ allegro5test.cpp -o allegro5test `allegro-config --libs`

但这不起作用.我正在使用 ubuntu 11.04.我使用 http://wiki.allegro.cc 中的说明安装了 allegro 5/index.php?title=Install_Allegro5_From_SVN/Linux/Debian

but that is not working. I'm using ubuntu 11.04. I installed allegro 5 using the instructions at http://wiki.allegro.cc/index.php?title=Install_Allegro5_From_SVN/Linux/Debian

我试过了:

g++ allegro5test.cpp -o allegro5test `allegro-config --cflags --libs`

而且它还给出了一堆未定义的错误,例如:未定义的对 `al_install_system' 的引用

And it also gives a bunch of undefined errors, like: undefined reference to `al_install_system'

allegro-config --cflags --libs 输出:

-I/usr/local/include
-L/usr/local/lib -lalleg

推荐答案

这样您就成功地从 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!
");
      return -1;
   }

   display = al_create_display(640, 480);
   if(!display) {
      fprintf(stderr, "failed to create display!
");
      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

这篇关于使用 allegro 5 和 g++ 编译 C++ 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆