1

我遇到了与下面链接中询问的人相同的错误。已经有答案了,但我该怎么做呢?谢谢你的帮助

https://stackoverflow.com/a/5294039/1333847

编辑1) 这是代码:

#include "allegro5/allegro.h"
#include "allegro5/allegro_image.h"
#include "allegro5/allegro_native_dialog.h"

int main(){

   ALLEGRO_DISPLAY *display = NULL;
   ALLEGRO_BITMAP  *image   = NULL;

   if(!al_init()) {
      al_show_native_message_box(display, "Error", "Error", "Failed to initialize allegro!", 
                                 NULL, ALLEGRO_MESSAGEBOX_ERROR);
      return 0;
   }

   if(!al_init_image_addon()) {
      al_show_native_message_box(display, "Error", "Error", "Failed to initialize al_init_image_addon!", 
                                 NULL, ALLEGRO_MESSAGEBOX_ERROR);
      return 0;
   }

   display = al_create_display(800,600);

   if(!display) {
      al_show_native_message_box(display, "Error", "Error", "Failed to initialize display!", 
                                 NULL, ALLEGRO_MESSAGEBOX_ERROR);
      return 0;
   }

   image = al_load_bitmap("image.png");

   if(!image) {
      al_show_native_message_box(display, "Error", "Error", "Failed to load image!", 
                                 NULL, ALLEGRO_MESSAGEBOX_ERROR);
      al_destroy_display(display);
      return 0;
   }

   al_draw_bitmap(image,200,200,0);

   al_flip_display();
   al_rest(2);

   al_destroy_display(display);
   al_destroy_bitmap(image);

   return 0;
}

这些是错误:

Undefined symbols for architecture x86_64:
  "_al_show_native_message_box", referenced from:
      __al_mangled_main in main.o
  "_al_init_image_addon", referenced from:
      __al_mangled_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

编辑2)记录此代码链接到代码一切正常

4

1 回答 1

3

Allegro 5 是模块化的。经验法则是,如果您使用的是#include <allegro5/allegro_...>,那么您需要与相应的库链接。在你的情况下:

_al_show_native_message_box: 链接-lallegro_native_dialog

_al_init_image_addon: 链接-lallegro_image

于 2012-04-27T01:54:02.470 回答