2017-03-10 58 views
0

運行快板我跑了BREW在OSX錯誤的OSX

安裝快板下面這個教程:https://wiki.allegro.cc/index.php?title=Example_ExHello

我的代碼

include <allegro.h> 

int main(void) { 
    if (allegro_init() != 0) 
    return 1; 

    /* set up the keyboard handler */ 
    install_keyboard(); 

    /* set a graphics mode sized 320x200 */ 
    if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) { 
    if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) { 
    set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); 
    allegro_message("Unable to set any graphic mode\n%s\n", allegro_error); 
    return 1; 
    } 
    } 

    /* set the color palette */ 
    set_palette(desktop_palette); 

    /* clear the screen to white */ 
    clear_to_color(screen, makecol(255, 255, 255)); 

    /* you don't need to do this, but on some platforms (eg. Windows) things 
    * will be drawn more quickly if you always acquire the screen before 
    * trying to draw onto it. 
    */ 
    acquire_screen(); 

    /* write some text to the screen with black letters and transparent background */ 
    textout_centre_ex(screen, font, "Hello, world!", SCREEN_W/2, SCREEN_H/2, makecol(0,0,0), -1); 

    /* you must always release bitmaps before calling any input functions */ 
    release_screen(); 

    /* wait for a keypress */ 
    readkey(); 

    return 0; 
} 



1.c:1:1: error: unknown type name 'include' 
include <allegro.h> 
^ 
1.c:1:9: error: expected identifier or '(' 
include <allegro.h> 
     ^
2 errors generated. 
make: *** [1] Error 1 

回答

0

假定該做include <allegro.h>的錯字應該是#include <allegro.h>,你已經安裝allegro5 - 的API是allegro4(此示例是從)和allegro5之間非常不同。顯示初始化sample program for allegro5顯示了一些差異:

#include <stdio.h> 
#include <allegro5/allegro.h> 

int main(int argc, char **argv){ 

    ALLEGRO_DISPLAY *display = NULL; 

    if(!al_init()) { // allegro_init in allegro4 
     fprintf(stderr, "failed to initialize allegro!\n"); 
     return -1; 
    } 

    display = al_create_display(640, 480); // very different to allegro4 
    if(!display) { 
     fprintf(stderr, "failed to create display!\n"); 
     return -1; 
    } 

    al_clear_to_color(al_map_rgb(0,0,0)); // makecol -> al_map_rgb, clear_to_color -> al_clear_to_color 

    al_flip_display(); 

    al_rest(10.0); 

    al_destroy_display(display); 

    return 0; 
} 

我建的使用:

c++ -I/usr/local/include allegro_display.cc -o allegro_display -L/usr/local/lib -lallegro -lallegro_main 

其中代碼是文件allegro_display.cc英寸請注意,我編譯使用C++編譯器,因爲快板確實是一個C++ API(當爲C代碼編譯因爲在C中的結構沒有適當的調用約定,樣品不工作,而沒有用於C++)

+0

我被誤以爲印象是一個純粹的C庫。謝謝,這會畫出一個黑色的矩形窗口。 – quantumpotato

+1

我對C VS C++問題的理由是,當我編譯C編譯器這個例子中,'al_map_rgb更換'al_map_rgb(0,0,0)'(255,255,255)'程序將與SEGV,這是崩潰通過使用C++編譯器來避免某種形式的二進制兼容性問題或其中*似乎*編譯器的問題。 – Petesh