在 Mac 上通过命令行编译 Allegro 5 程序

Sma*_*nts 3 c++ macos command-line g++ allegro5

我按照步骤从他们的 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;
}
Run Code Online (Sandbox Code Playgroud)

我是使用 Unix 的新手,并且只用 g++ 编译过 C++ 程序,这些程序是简单的 hello world 文件,不需要库。

因此,在互联网上搜索后,我尝试了以下命令:

g++ hello.cpp -o hello `pkg-config --libs allegro-5`
Run Code Online (Sandbox Code Playgroud)

结果如下:

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
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我使用自制软件来安装依赖项而不是 macports

brew install pkg-config brew install zlib 等等...

这似乎是一个链接问题。

我究竟做错了什么?

Cle*_*rix 7

尝试使用自制软件安装快板并使用gcc -o main main.c -lallegro -lallegro_main

因为 allegro_main 是一个兼容库,它允许 main 函数在所有编译器上工作。仅从 OS X 需要。