我一直在尝试使用Allegro 5.2版本,但由于某种原因,我无法使用MinGW在我的系统(运行Windows 10 64位)上进行编译。
这是我想要链接的内容。根据维基,这应该是正确的,但每当我尝试编译示例代码时,我都会遇到错误
src\game.c|13|undefined reference to `al_clear_to_color'|
对于我所知道的人来说,这个功能应该存在。
我非常感谢任何帮助:)
这是一个无法编译的代码示例
#include"../include/init.h"
#include "allegro5/allegro5.h"
#include"allegro5/allegro_audio.h"
#include"allegro5/allegro_acodec.h"
#include<stdio.h>
#include<stdlib.h>
const float fps = 30;
const int width = 256;
const int height = 240;
int init() {
running = 1;
if(!al_init()) {
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}
timer = al_create_timer(1.0 / fps);
if(!timer) {
fprintf(stderr, "failed to create timer!\n");
return -1;
}
display = al_create_display(width, height);
if(!display) {
fprintf(stderr, "failed to create display!\n");
return -1;
}
event_queue = al_create_event_queue();
if(!event_queue) {
fprintf(stderr, "failed to create event_queue!\n");
return -1;
}
/*if(!al_install_audio()){
fprintf(stderr, "failed to initialize audio!\n");
return -1;
}
if(!al_install_keyboard()) {
fprintf(stderr, "failed to initialize the keyboard!\n");
return -1;
}
if(!al_init_acodec_addon()){
fprintf(stderr, "failed to initialize audio codecs!\n");
return -1;
}
if (!al_reserve_samples(1)){
fprintf(stderr, "failed to reserve samples!\n");
return -1;
}*/
if(!al_init_primitives_addon()) {
fprintf(stderr, "failed to create primitives addon");
return -1;
}
al_register_event_source(event_queue, al_get_display_event_source(display));
// register timer event for max fps
al_register_event_source(event_queue, al_get_timer_event_source(timer));
//al_register_event_source(event_queue, al_get_keyboard_event_source());
al_clear_to_color(al_map_rgb(0,0,0));
al_flip_display();
al_start_timer(timer);
return 1;
}
正在使用al_map_rgb_f()
函数来映射颜色,如下所示:al_clear_to_color(al_map_rgb(255, 255, 255));
?
你能在这里插入你的代码吗?
对不起,这不应该是一个答案,因为虽然我没有评论它的声誉。
我可以在链接器设置中看到,您分别链接整体版本和所有模块。 monolith版本是所有其他模块组合成一个,使您不需要所有其他allegro_ *库。也许那里有冲突?除此之外,请检查日志并检查调试和发布是否存在问题。
您的链接器设置都搞砸了。您正在混合动态和静态库,以及单片和非单片库。
以.dll.a结尾的库是导入存档。仅以.a结尾的库是静态库存档。当您链接到动态allegro monolith时,您不需要链接到任何其他内容。
当您链接到静态allegro库时,您还必须链接它们的依赖项。
另外,我通常不建议使用代码块项目链接器设置中的“链接库”窗格。设置链接器包括directores和链接器选项。它允许您随意更改链接目录,而无需更改任何库链接选项。这样,您可以随意升级您的allegro和其他库。否则,您必须删除并重新添加所有链接库。