【发布时间】:2015-03-04 04:15:01
【问题描述】:
我按照步骤从他们的 wiki(在此处找到: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
顺便说一句,我使用自制软件来安装依赖项而不是 macports
brew install pkg-config 冲泡安装zlib 等等……
这似乎是一个链接问题。
我做错了什么?
【问题讨论】:
-
尝试使用
$(pkg-config --libs allegro-5)而不是`pkg-config --libs allegro-5` -
我刚刚尝试过,它会导致同样的错误。我认为这与未正确链接的事物有关,但我不知道如何解决。
-
您是在尝试使用静态库还是动态库进行编译?命令的输出是什么:
pkg-config --libs allegro-5 -
我正在使用静态库(至少我认为我是。请参见此处:wiki.allegro.cc/index.php?title=Install_Allegro5_From_GIT/…)“使用 make 构建静态快板”输出为:-L/usr/local/lib -lallegro跨度>
-
很好,把它作为答案并接受它。 :) (一定是
allegro_main-5的关键部分)?。
标签: c++ macos command-line g++ allegro5