本文介绍了在OSX上运行Allegro 5时,找不到主要功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图获得一个在OSX上运行Allegro的最小示例。
I am trying to get a minimal example of Allegro running on OSX.
我使用Homebrew安装了稳定版的Allegro 5.2,中指定。
I installed the stable version Allegro 5.2 using Homebrew, as specified in the Allegro wiki.
这是我的代码( allegro.hpp
):
/*
* This program uses the Allegro game library to display a blank window.
*
* It initializes the display and starts up the main game loop. The
* game loop only checks for two events: timer (determined by the FPS)
* and display close (when the user tries to close the window).
*
* http://www.damienradtke.org/building-a-mario-clone-with-allegro
*/
#include <stdio.h>
#include <allegro5/allegro.h>
constexpr float FPS = 60.0f;
int main(int argc, char** argv) {
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
ALLEGRO_TIMER *timer = NULL;
bool running = true;
bool redraw = true;
// Initialize allegro
if (!al_init()) {
fprintf(stderr, "Failed to initialize allegro.\n");
return 1;
}
// Initialize the timer
timer = al_create_timer(1.0f / FPS);
if (!timer) {
fprintf(stderr, "Failed to create timer.\n");
return 1;
}
// Create the display
display = al_create_display(640, 480);
if (!display) {
fprintf(stderr, "Failed to create display.\n");
return 1;
}
// Create the event queue
event_queue = al_create_event_queue();
if (!event_queue) {
fprintf(stderr, "Failed to create event queue.");
return 1;
}
// Register event sources
al_register_event_source(event_queue, al_get_display_event_source(display));
al_register_event_source(event_queue, al_get_timer_event_source(timer));
// Display a blank screen
al_clear_to_color(al_map_rgb(100, 149, 237));
al_flip_display();
// Start the timer
al_start_timer(timer);
// Game loop
while (running) {
ALLEGRO_EVENT event;
ALLEGRO_TIMEOUT timeout;
// Initialize timeout
al_init_timeout(&timeout, 0.06);
// Fetch the event (if one exists)
bool get_event = al_wait_for_event_until(event_queue, &event, &timeout);
// Handle the event
if (get_event) {
switch (event.type) {
case ALLEGRO_EVENT_TIMER:
redraw = true;
break;
case ALLEGRO_EVENT_DISPLAY_CLOSE:
running = false;
break;
default:
fprintf(stderr, "Unsupported event received: %d\n", event.type);
break;
}
}
// Check if we need to redraw
if (redraw && al_is_event_queue_empty(event_queue)) {
// Redraw
al_clear_to_color(al_map_rgb(100, 149, 237));
al_flip_display();
redraw = false;
}
}
// Clean up
al_destroy_display(display);
al_destroy_event_queue(event_queue);
return 0;
}
这是我的build和execute命令:
Here is my build and execute command:
$ clang++ -I/usr/local/include/ -L/usr/local/lib -lallegro -lallegro_main allegro.hpp -std=c++14 && ./a.out
这里是我收到的错误:
dyld: Symbol not found: __al_mangled_main
Referenced from: /usr/local/opt/allegro/lib/liballegro_main.5.2.dylib
Expected in: flat namespace
in /usr/local/opt/allegro/lib/liballegro_main.5.2.dylib
Trace/BPT trap: 5
我已经尝试过其他地方提供的解决方案:
I have already tried the solution given elsewhere:
- 函数的签名
int main(int argc,char ** argv)
- 链接
liballegro_main.dylib
推荐答案
您命名为 allegro.hpp
You named it allegro.hpp
, even though it is a source file, not a header file.
这篇关于在OSX上运行Allegro 5时,找不到主要功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!