c++c++11gccallegroallegro5

Allegro 5 game won't compile with GCC


I'm trying to port over a game that I made using Allegro 5.0 (from Windows to a Raspberry Pi running Raspian). I installed Allegro and moved over all my source files, but when I try to compile using: *g++ -std=c++0x .cpp -o SpaceFighter $(pkg-config --libs allegro-5) I get the following:

/tmp/ccBliSky.o: In function main': main.cpp:(.text+0x130): undefined reference toal_show_native_message_box' main.cpp:(.text+0x160): undefined reference to al_init_font_addon' main.cpp:(.text+0x164): undefined reference toal_init_ttf_addon' main.cpp:(.text+0x168): undefined reference to al_init_image_addon' main.cpp:(.text+0x1a4): undefined reference toal_load_ttf_font' main.cpp:(.text+0x574): undefined reference to al_draw_textf' /tmp/ccBMyqom.o: In functionMenuItem::MenuItem()': MenuItem.cpp:(.text+0xa0): undefined reference to al_load_ttf_font' /tmp/ccBMyqom.o: In functionMenuItem::~MenuItem()': MenuItem.cpp:(.text+0x1ac): undefined reference to al_destroy_font' /tmp/ccBMyqom.o: In functionMenuItem::Draw(GameTime const*)': MenuItem.cpp:(.text+0x2fc): undefined reference to al_draw_text' /tmp/ccKXP3ds.o: In functionPlayerShip::SetAudioSample(std::string)': PlayerShip.cpp:(.text+0x604): undefined reference to al_destroy_sample' PlayerShip.cpp:(.text+0x64c): undefined reference toal_load_sample' collect2: error: ld returned 1 exit status

AND NO THIS IS NOT A DUPLICATE OF "What are undefined reference/unresolved external symbol errors? What are common causes and how to fix/prevent them?"

I know what usually causes most undefined reference errors. This question is specific to the allegro library I'm using.

Here's a bit of code (I'm obviously not going to post the whole game):

#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();

Thanks in advance for any help!


Solution

  • Alegro divides its functionality across several modules. Your pkg-config line must include all the modules you are using. Try the following:

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