2012-04-26 61 views
1

我收到了與下面鏈接中詢問的人相同的錯誤。已經有了答案,但我到底該怎麼做?感謝您的幫助如何強制OS X上的_al_mangled_main的「默認」可見性?

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

EDIT1)這是代碼:

#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) 

EDIT2)使用此代碼記錄link to a code一切正常

+0

?如果您使用的是5.0.0以上的版本,這應該不成問題。 – Matthew 2012-04-26 22:13:54

+0

實際上我使用的是5.1(不穩定)分支。甚至試過了svn的5(穩定)版本(應該是最新的版本),仍然是一樣的 – Markus 2012-04-26 22:15:47

+0

你應該在你的問題中包含你的錯誤消息的詳細信息,以防萬一有些不同。 (例如,忘記與-lallegro_main鏈接) – Matthew 2012-04-26 22:34:54

回答

3

Allegro 5是模塊化的。經驗法則是,如果您使用#include <allegro5/allegro_...>,則需要鏈接相應的庫。你的情況:

_al_show_native_message_box:鏈接與-lallegro_native_dialog

_al_init_image_addon:鏈接與-lallegro_image您正在使用什麼版本的快板

+0

實際上這工作! :)非常感謝你 – Markus 2012-04-27 07:28:08

+0

我節省了時間..謝謝 – 2013-03-02 01:28:14