在osx上使用gcc编译allegro5程序时出错

时间:2017-04-20 16:05:10

标签: c macos gcc allegro

我正在尝试在Mac OSX 10.12上编译一个简单的allegro5程序,但我得到一个未定义的符号错误。这是我在终端中运行的命令

gcc main.c -o hello -I/usr/local/include/ -L/usr/local/lib -lallegro_main

这是我的代码。

#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;
}

这是我得到的错误

Undefined symbols for architecture x86_64:
  "_al_clear_to_color", referenced from:
      __al_mangled_main in main-b86b99.o
  "_al_create_display", referenced from:
      __al_mangled_main in main-b86b99.o
  "_al_destroy_display", referenced from:
      __al_mangled_main in main-b86b99.o
  "_al_flip_display", referenced from:
      __al_mangled_main in main-b86b99.o
  "_al_install_system", referenced from:
      __al_mangled_main in main-b86b99.o
  "_al_map_rgb", referenced from:
      __al_mangled_main in main-b86b99.o
  "_al_rest", referenced from:
      __al_mangled_main in main-b86b99.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我可能没有正确安装allegro吗?我根据allegro维基说明使用自制软件安装它。 https://wiki.allegro.cc/index.php?title=Getting_Started#Mac_OS

1 个答案:

答案 0 :(得分:0)

这些是链接器错误。您需要链接到lallegro