2017-04-20 86 views
0

我想在Mac OSX 10.12上編譯一個簡單的allegro5程序,但得到一個未定義的符號錯誤。下面是我在終端在osx上使用gcc編譯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 wiki的說明,我使用自制軟件安裝了它。 https://wiki.allegro.cc/index.php?title=Getting_Started#Mac_OS

回答

0

這些是鏈接器錯誤。您需要鏈接到lallegro

+0

這就是'-lallegro_main'的用途。據我所知,搜索路徑和庫路徑是正確的。 –

+0

'lallegro'與'lallegro_main'不一樣。 'lallegro'提供了大部分的核心功能,'lallegro_main'只是主要功能(我認爲這只是MacOS所必需的)。雖然我沒有看到'al_init'的未定義參考,所以我可能在這裏是錯的... – rcorre

+0

'allegro_main'模塊[依賴於](http://liballeg.org/a5docs/trunk/getting_started.html) 'allegro'模塊。因此,除了'lallegro_main'外,我會嘗試在您的'gcc'調用中添加'-lallegro'標誌 – rcorre