在OSX上运行Allegro时出错(Error running Allegro on OSX)

系统教程 行业动态 更新时间:2024-06-14 17:02:17
在OSX上运行Allegro时出错(Error running Allegro on OSX)

我在OSX上运行brew install allegro

遵循本教程: 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

I ran brew install allegro on OSX

following this tutorial: https://wiki.allegro.cc/index.php?title=Example_ExHello

my code

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

最满意答案

假定include <allegro.h>的打字错误应该是#include <allegro.h> ,您已经安装了allegro5 - 在allegro4(本例来自这个例子)和allegro5之间,API非常不同。 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 ++编译器进行编译,因为allegro实际上是一个C ++ api(并且当编译为C代码时,该示例不起作用,因为C中没有适当的调用约定,而C ++中有)

Presuming that the typo of doing include <allegro.h> was supposed to be #include <allegro.h>, You've installed allegro5 - the API is very different between allegro4 (which this example is from) and allegro5. The display initialization sample program for allegro5 shows some of the differences:

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

I built it using:

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

where the code was in the file allegro_display.cc. Note that I compile using the C++ compiler, because allegro is really a C++ api (and the sample does not work when compiled as C code because there is no proper calling convention for structs in C, whereas there is for C++)

更多推荐

本文发布于:2023-04-21 18:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/c1af711c7ae6abf3b2a3ed5808778ec6.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Allegro   OSX   running   Error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!