快板 5 游戏无法使用 GCC 编译
Allegro 5 game won't compile with GCC
我正在尝试移植我使用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 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::D raw(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 个退出状态
不,这不是"什么是未定义的参考/未解决的外部符号错误?常见原因是什么以及如何修复/预防它们?
我知道通常是什么导致了大多数未定义的引用错误。这个问题特定于我正在使用的快板库。
这里有一些代码(我显然不会发布整个游戏):
#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
- 为什么 gcc 编译这个而 msvc 没有
- 错误:使用 clang 没有可行的重载,使用 GCC 编译
- 带有自动参数的函数使用 GCC 编译,但不使用 Visual C++ 编译
- 使用 MINGW gcc 编译时,不会为 std::string 调用重载的新运算符
- Steam 回调在 Linux / GCC 编译期间触发警告
- 在其他容器中使用 boost::container::static_vector 时,GCC 编译错误"将'const s'绑定到类型's&'的引用丢弃限定符"
- 如何使用 GCC 编译指示启用选项 '-Werror'?
- 如何实现使用 gcc-4.4 编译的大向量初始化?
- 关于这个在 Linux 上使用 gcc 编译的程序中的 vtable,nm 告诉我什么?
- 使用 TDM GCC 5.1.0 编译 PDCurses36 时出错
- 为什么这段代码无法使用 gcc 4.8.5 编译,而使用 clang 编译正常
- 使用 std::addressof 时出现 GCC 7 编译错误
- 在类模板上使用 arm gcc 编译期间的隔离错误
- 使用 GCC 编译C++时如何包含 C11 标头?
- 类数据成员指针的非类型模板参数包无法使用 gcc 编译
- 是否可以使用 GCC 编译具有特定编译器标志的代码文件的一部分?
- 将 cctype 函数分配给 std::function,gcc 编译错误
- GCC 编译时出现警告:未知转义序列:"\040"
- 为什么以下代码不使用GCC编译,而是用Clang编译罚款
- GCC编译器,为较低版本的GCC编译应用程序