【问题标题】:Allegro 5 game won't compile with GCCAllegro 5 游戏无法使用 GCC 编译
【发布时间】:2017-03-17 05:07:23
【问题描述】:

我正在尝试移植我使用 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 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::Draw(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 个退出状态

这不是“什么是未定义的引用/未解决的外部符号错误?什么是常见原因以及如何修复/预防它们?”的重复。

我知道通常会导致大多数未定义的引用错误的原因。这个问题是针对我正在使用的 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();

提前感谢您的帮助!

【问题讨论】:

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


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

    -lallegro_dialog
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-16
      • 2020-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多