用allegro 5和g ++编译C ++代码 [英] Compiling C++ code with allegro 5 and g++
问题描述
为了使用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!\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
这篇关于用allegro 5和g ++编译C ++代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!