unlink
unlink

Reputation: 1

Allegro 5.2 compilation errors

I've been trying to work with Allegro version 5.2, but for some reason I cannot get it to compile on my System (running Windows 10 64 bit) using MinGW.

My Linker Settings

here's what I'm trying to link. According to the wiki this should be right, but whenever I try to compile sample code I get errors such as

src\game.c|13|undefined reference to `al_clear_to_color'|

This function should be present for all I know.

I really appreciate any help :)

Here's an example of code that won't compile

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

Upvotes: 0

Views: 446

Answers (3)

BugSquasher
BugSquasher

Reputation: 335

Your linker settings are all messed up. You're mixing both dynamic and static libraries, as well as monolithic and non-monolithic libraries.

Libraries ending in .dll.a are import archives. Libraries ending in just .a are static library archives. When you link to the dynamic allegro monolith, you do not need to link to anything else.

When you link to the static allegro libraries, you must link their dependencies as well.

As an aside, I generally don't recommend using the 'link libraries' pane in the Code Blocks project linker settings. Set the linker include directores and the linker options instead. It allows you to change your link directory at will without changing any library link options. That way, you can upgrade your allegro and other libraries at will. Otherwise you have to remove and re-add all the link libraries.

Upvotes: 0

kraxie
kraxie

Reputation: 11

I can see in your linker settings that you both link the monolith version and all modules separately. The monolith version is all other modules combined into one, making you only not need all the other allegro_* libraries. Maybe there's a conflict there? Other than that, check the log and check if the issue is both with Debug and Release.

Upvotes: 0

Aipi
Aipi

Reputation: 2476

Are using al_map_rgb_f() function to mapping the color, like this: al_clear_to_color(al_map_rgb(255, 255, 255));?

Can you insert your code here?

Sorry, it shouldn't be an answer, for while I don't have a reputation to comment it.

Upvotes: 0

Related Questions