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

标签 c++ c++11 gcc allegro allegro5

我正在尝试移植我使用 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/

相关文章:

C++ 分析 : clock cycle count

multithreading - 多线程,为什么此串行代码比其并行版本要快?

c++ - 这本教科书错了吗?专门化某些成员函数而不是其他成员函数

c - 32位Linux上 "_Jv_RegisterClasses"和 "clock_gettime"在哪里定义的?

c++ - 使用 clang 选择特定的 libstdc++ 版本

c++ - vector 插入和分配之间的区别

c++ - 基本的 string.h 问题(C++)

c++ - 为什么 std::vector 是连续的?

c++11 - C++ 11编译失败, undefined reference ,另一个类内部的显式模板类实例化

c++ - 可变大小的 char[] - 可以吗?