在Mac上通过命令行编译Allegro 5程序
Compiling Allegro 5 Program through command line on a Mac
我按照步骤从他们的wiki构建和安装Allegro 5(在这里找到:https://wiki.allegro.cc/index.php?title=Main_Page)并且似乎毫无问题地成功了。
allegro被安装到以下位置(正如wiki所建议的)/usr/local/include和/usr/local/lib,我已经确认allegro在那里。
然后我在vim中编写了以下代码:
#include <stdio.h>
#include <allegro5/allegro.h>
int main(int argc, char **argv)
{
ALLEGRO_DISPLAY *display = NULL;
if(!al_init())
{
fprintf(stderr, "failed to initialize allegro!n");
return -1;
}
display = al_create_display(640, 480);
if(!display)
{
fprintf(stderr, "failed to create display!n");
return -1;
}
al_clear_to_color(al_map_rgb(0,0,0));
al_flip_display();
al_rest(10.0);
al_destroy_display(display);
return 0;
}
我是Unix的新手,只用g++编译过c++程序,这些程序是简单的helloworld文件,不需要库。
因此,在互联网上搜索后,我尝试了以下命令:
g++ hello.cpp -o hello `pkg-config --libs allegro-5`
结果如下:
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
(maybe you meant: __al_mangled_main)
ld: symbols not found for architecture x86_64
clang: error: linker command failed with exit code 1
顺便说一句,我用自制软件安装依赖项,而不是macports
brew安装pkg配置brew安装zlib等等。
这似乎是一个联系问题。
我做错了什么?
尝试用自制软件安装allegro并使用gcc -o main main.c -lallegro -lallegro_main
因为allegro_main是一个兼容性库,它允许main函数在所有编译器上工作。仅OS X需要。