Allegro 5 游戏无法使用 GCC 编译
Allegro 5 game won't compile with GCC
我正在尝试移植我使用 Allegro 5.0 制作的游戏(从 Windows 到 Raspberry Pi 运行 Raspian)。我安装了 Allegro 并移动了所有源文件,但是当我尝试使用以下命令进行编译时:*g++ -std=c++0x .cpp -o SpaceFighter $(pkg-config -- libs allegro-5) 我得到以下信息:
/tmp/ccBliSky.o: 在函数中 main':
main.cpp:(.text+0x130): undefined reference to
al_show_native_message_box'
main.cpp:(.text+0x160): 对 al_init_font_addon'
main.cpp:(.text+0x164): undefined reference to
al_init_ttf_addon 的未定义引用
main.cpp:(.text+0x168): 对 al_init_image_addon'
main.cpp:(.text+0x1a4): undefined reference to
al_load_ttf_font 的未定义引用
main.cpp:(.text+0x574): 对 al_draw_textf'
/tmp/ccBMyqom.o: In function
MenuItem::MenuItem()' 的未定义引用:
MenuItem.cpp:(.text+0xa0): 对 al_load_ttf_font'
/tmp/ccBMyqom.o: In function
MenuItem::~MenuItem() 的未定义引用:
MenuItem.cpp:(.text+0x1ac): 对 al_destroy_font'
/tmp/ccBMyqom.o: In function
MenuItem::Draw(GameTime const*)' 的未定义引用:
MenuItem.cpp:(.text+0x2fc): 对 al_draw_text'
/tmp/ccKXP3ds.o: In function
PlayerShip::SetAudioSample(std::string)' 的未定义引用:
PlayerShip.cpp:(.text+0x604): 未定义引用 al_destroy_sample'
PlayerShip.cpp:(.text+0x64c): undefined reference to
al_load_sample'
collect2:错误:ld 返回了 1 个退出状态
而且这不是 "What are undefined reference/unresolved external symbol errors? What are common causes and how to fix/prevent them?"
的重复
我知道通常导致大多数未定义引用错误的原因。这个问题特定于我正在使用的 allegro 库。
这里有一些代码(我显然不会 post 整个游戏):
#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
我正在尝试移植我使用 Allegro 5.0 制作的游戏(从 Windows 到 Raspberry Pi 运行 Raspian)。我安装了 Allegro 并移动了所有源文件,但是当我尝试使用以下命令进行编译时:*g++ -std=c++0x .cpp -o SpaceFighter $(pkg-config -- libs allegro-5) 我得到以下信息:
/tmp/ccBliSky.o: 在函数中 main':
main.cpp:(.text+0x130): undefined reference to
al_show_native_message_box'
main.cpp:(.text+0x160): 对 al_init_font_addon'
main.cpp:(.text+0x164): undefined reference to
al_init_ttf_addon 的未定义引用
main.cpp:(.text+0x168): 对 al_init_image_addon'
main.cpp:(.text+0x1a4): undefined reference to
al_load_ttf_font 的未定义引用
main.cpp:(.text+0x574): 对 al_draw_textf'
/tmp/ccBMyqom.o: In function
MenuItem::MenuItem()' 的未定义引用:
MenuItem.cpp:(.text+0xa0): 对 al_load_ttf_font'
/tmp/ccBMyqom.o: In function
MenuItem::~MenuItem() 的未定义引用:
MenuItem.cpp:(.text+0x1ac): 对 al_destroy_font'
/tmp/ccBMyqom.o: In function
MenuItem::Draw(GameTime const*)' 的未定义引用:
MenuItem.cpp:(.text+0x2fc): 对 al_draw_text'
/tmp/ccKXP3ds.o: In function
PlayerShip::SetAudioSample(std::string)' 的未定义引用:
PlayerShip.cpp:(.text+0x604): 未定义引用 al_destroy_sample'
PlayerShip.cpp:(.text+0x64c): undefined reference to
al_load_sample'
collect2:错误:ld 返回了 1 个退出状态
而且这不是 "What are undefined reference/unresolved external symbol errors? What are common causes and how to fix/prevent them?"
的重复我知道通常导致大多数未定义引用错误的原因。这个问题特定于我正在使用的 allegro 库。
这里有一些代码(我显然不会 post 整个游戏):
#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