我按照他们的维基(这里是:https://wiki.allegro.cc/index.php?title=Main_Page)构建和安装Allegro 5的步骤,似乎成功了,没有任何问题。
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++程序,这些程序是简单的hello world文件,不需要库。
因此,在互联网上搜索后,我尝试了以下命令:
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顺便说一句,我使用自制软件来安装依赖项,而不是macport。
brew install pkg-config brew install zlib等...
这看起来像是一个链接问题。
我做错了什么?
发布于 2017-09-24 18:55:49
尝试使用homebrew和gcc -o main main.c -lallegro -lallegro_main安装allegro
因为allegro_main是一个兼容性库,它允许main函数在所有编译器上工作。仅在OS X中需要。
https://stackoverflow.com/questions/28846566
复制相似问题