gpt4 book ai didi

c++ - Allegro 5 游戏无法使用 GCC 编译

转载 作者:行者123 更新时间:2023-11-28 01:51:35 27 4
gpt4 key购买 nike

我正在尝试移植我使用 Allegro 5.0 制作的游戏(从 Windows 到运行 Raspian 的 Raspberry Pi)。我安装了 Allegro 并移动了所有源文件,但是当我尝试使用以下命令进行编译时:*g++ -std=c++0x .cpp -o SpaceFighter $(pkg-config --libs allegro-5 ) 我得到以下信息:

/tmp/ccBliSky.o: 在函数 main' 中:
main.cpp:(.text+0x130): undefined reference
al_show_native_message_box'main.cpp:(.text+0x160): 未定义对 al_init_font_addon 的引用
main.cpp:(.text+0x164): undefined reference
al_init_ttf_addon'main.cpp:(.text+0x168): 对 al_init_image_addon' 的 undefined reference
main.cpp:(.text+0x1a4): undefined reference
al_load_ttf_font'main.cpp:(.text+0x574): 未定义对 al_draw_textf 的引用
/tmp/ccBMyqom.o: 在函数中
MenuItem::MenuItem()':MenuItem.cpp:(.text+0xa0): 未定义对 al_load_ttf_font 的引用'
/tmp/ccBMyqom.o: 在函数中
MenuItem::~MenuItem()':MenuItem.cpp:(.text+0x1ac): 未定义对 al_destroy_font 的引用
/tmp/ccBMyqom.o: 在函数中
MenuItem::Draw(GameTime const*)':MenuItem.cpp:(.text+0x2fc): 未定义对 al_draw_text 的引用
/tmp/ccKXP3ds.o: 在函数中
PlayerShip::SetAudioSample(std::string)':PlayerShip.cpp:(.text+0x604): 未定义对 al_destroy_sample 的引用'
PlayerShip.cpp:(.text+0x64c): undefined reference
al_load_sample'collect2:错误:ld 返回 1 退出状态

这不是“什么是 undefined reference /未解析的外部符号错误?常见原因是什么以及如何修复/预防它们?”的重复

我知道通常导致大多数 undefined reference 错误的原因。这个问题特定于我正在使用的 allegro 库。

这里有一些代码(我显然不会发布整个游戏):

#include <allegro5/allegro.h>
#include <allegro5/allegro_native_dialog.h>

#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_image.h>

#include <iostream>

#include "Game.h"


int main(int argc, char *argv[])
{
const char errorType[] = "Initialization Error";
const int flags = ALLEGRO_MESSAGEBOX_ERROR;

// Initialize Allegro
if (!al_init())
{
const char message[] = "Failed to initialize Allegro Library.";
//al_show_native_message_box(nullptr, "Error", errorType, message, nullptr, flags);
return -1;
}

Game game;

// Initialize a new window for gameplay.

int screenWidth = Game::GetScreenWidth();
int screenHeight = Game::GetScreenHeight();

在此先感谢您的帮助!

最佳答案

Alegro 将其功能划分为多个模块。您的 pkg-config 行必须包含您正在使用的所有模块。尝试以下操作:

pkg-config --libs allegro-5 allegro_font-5 allegro_image-5 allegro_ttf-5

关于c++ - Allegro 5 游戏无法使用 GCC 编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42849623/

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