gpt4 book ai didi

c++ - 使用 allegro 5 和 g++ 编译 C++ 代码

转载 作者:太空狗 更新时间:2023-10-29 20:06:45 27 4
gpt4 key购买 nike

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

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

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

我试过:

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

而且它还给出了一堆未定义的错误,比如:undefined reference to `al_install_system'

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

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

最佳答案

因此,您已经通过 SVN 在您的系统上成功安装了 allegro5。您应该知道的一件事是,此构建不附带 allegro-config。如果您的系统上有它,则表示您之前已经安装了 allegro4

allegro5 带来了许多变化,包括不同的初始化程序、库和函数名称。

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

#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 不同:

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

关于c++ - 使用 allegro 5 和 g++ 编译 C++ 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6377204/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com