快板 5 游戏无法使用 GCC 编译

Allegro 5 game won't compile with GCC

本文关键字:GCC 编译 游戏 快板      更新时间:2023-10-16

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

/tmp/ccBliSky.o: In functionmain': main.cpp:(.text+0x130): undefined reference toal_show_native_message_box' main.cpp:(.text+0x160):未定义对al_init_font_addon' main.cpp:(.text+0x164): undefined reference toal_init_ttf_addon的引用 main.cpp:(.text+0x168):对al_init_image_addon' main.cpp:(.text+0x1a4): undefined reference toal_load_ttf_font的未定义引用 main.cpp:(.text+0x574): 对al_draw_textf' /tmp/ccBMyqom.o: In functionMenuItem::MenuItem()'的未定义引用: MenuItem.cpp:(.text+0xa0): 未定义对al_load_ttf_font' /tmp/ccBMyqom.o: In functionMenuItem::~MenuItem()'的引用: MenuItem.cpp:(.text+0x1ac): 未定义对al_destroy_font' /tmp/ccBMyqom.o: In functionMenuItem::D raw(GameTime const*)'的引用: MenuItem.cpp:(.text+0x2fc): 未定义对al_draw_text' /tmp/ccKXP3ds.o: In functionPlayerShip::SetAudioSample(std::string)'的引用: PlayerShip.cpp:(.text+0x604):未定义对al_destroy_sample' PlayerShip.cpp:(.text+0x64c): undefined reference toal_load_sample的引用 collect2:错误:ld 返回 1 个退出状态

不,这不是"什么是未定义的参考/未解决的外部符号错误?常见原因是什么以及如何修复/预防它们?

我知道通常是什么导致了大多数未定义的引用错误。这个问题特定于我正在使用的快板库。

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

#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

我在al_show_native_message_box函数上遇到了同样的问题,我通过添加以下标志解决了它:

-lallegro_dialog