c++ - 编译 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 标志,我希望这些库能够正确链接。我错过了什么?
解决方案
推荐阅读
- msbuild - 如何将 NuGet contentFiles 提取到特定目录?
- typescript - 由于 google-cloud 包中的问题,TSC 构建失败,
- java - 如何为 Google Cloud API 生成访问令牌?
- java - 如何从网络 selenium+Java 获取查询字符串参数
- windows - Windows 命令删除现有目录并创建新目录
- powerbi - 在 Power BI Desktop DAX 论坛中应用筛选器的问题
- excel - 如何将所有工作表内容保存在一个变量中,然后将其返回到我的工作表?
- python - 我在 spyder 中有 python 脚本,我希望它每天下午 4 点运行
- c# - 请求被中止:使用 X509Certificate2 时无法创建 SSL/TLS 安全通道
- regex - 我如何匹配不包括这些的引号之间的内容?