首页 > 解决方案 > 编译 Allegro 代码时未定义的符号

问题描述

我正在尝试在 Mac OS Catalina 10.15.4 上开始使用适用于 C++ 的 Allegro 游戏开发库,但我在编译和链接方面遇到了一些问题。以下代码编译:

#include <stdio.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_font.h>
#include <iostream>

#define ScreenWidth 375
#define ScreenHeight 667

int main(int argc, char *argv[]){
  
  al_init();
  /*
  al_init_font_addon();
  al_init_ttf_addon();
  */
  ALLEGRO_DISPLAY* display;
  //ALLEGRO_FONT* font = al_load_ttf_font("aArang.ttf",64,0);
  display= al_create_display(ScreenWidth,ScreenHeight);
  al_set_window_position(display,200,100);
  al_set_window_title(display, "Grapevine Groove");
  while(true){
    al_clear_to_color(al_map_rgb(255,255,255));
    //al_draw_text(font,al_map_rgb(0,0,0),0,0,0,"Hello World!");
    al_flip_display();
  }
  al_rest(1.0);
  return 0;
}

但是,如您所见,从 Allegro 中引用某些包的行被注释掉了。当这些行未注释和编译时,它们不会链接到正确的包。我搜索了不同的论坛并尝试以各种方式编辑我的 makefile 无济于事。我看到 Allegro 可以使用整体设置进行编译以链接其所有包,但我不确定是否/如何使用我的 Allegro 版本(我想我有 5.2.6)来执行此操作。链接错误如下:

Undefined symbols for architecture x86_64:
  "_al_draw_text", referenced from:
      __al_mangled_main in GrapevineGroove-0fd63a.o
  "_al_init_font_addon", referenced from:
      __al_mangled_main in GrapevineGroove-0fd63a.o
  "_al_init_ttf_addon", referenced from:
      __al_mangled_main in GrapevineGroove-0fd63a.o
  "_al_load_ttf_font", referenced from:
      __al_mangled_main in GrapevineGroove-0fd63a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [clean] Error 1

我读到附加组件必须与主 Allegro 库分开安装在 Windows 和 Linux 上,但我通过 Homebrew 安装了 Allegro,但不确定它是如何工作的。

编辑:我忘了包括我的makefile的内容:

clean:
    g++ -g GrapevineGroove.cpp -Wall -Wextra -I/usr/include/allegro5 -L/usr/lib -lallegro -lallegro_main -o GrapevineGroove

通过 -l 标志,我希望这些库能够正确链接。我错过了什么?

标签: c++macosallegro5

解决方案


推荐阅读