getting this
1>main_display.obj : error LNK2005: "struct ALLEGRO_DISPLAY * main_display" (?main_display@@3PAUALLEGRO_DISPLAY@@A) already defined in event_queue.obj
1>main.obj : error LNK2005: "struct ALLEGRO_DISPLAY * main_display" (?main_display@@3PAUALLEGRO_DISPLAY@@A) already defined in event_queue.obj
1>main.obj : error LNK2005: "struct ALLEGRO_TIMER * timer" (?timer@@3PAUALLEGRO_TIMER@@A) already defined in event_queue.obj
1>main.obj : error LNK2005: "struct ALLEGRO_EVENT_QUEUE * event_queue" (?event_queue@@3PAUALLEGRO_EVENT_QUEUE@@A) already defined in event_queue.obj
1>main_timer.obj : error LNK2005: "struct ALLEGRO_TIMER * timer" (?timer@@3PAUALLEGRO_TIMER@@A) already defined in event_queue.obj
Any Idea what can cause this?
EDIT:
main_display.h:
#pragma once
#include <allegro5/allegro.h>
#include <stdio.h>
#define SCREEN_W 640
#define SCREEN_H 480
extern ALLEGRO_DISPLAY *main_display = NULL;
void display_init();
void destroy_display();
event_queue.h
#pragma once
#include <stdio.h>
#include <allegro5/allegro.h>
#include "main_timer.h"
#include "main_display.h"
extern ALLEGRO_EVENT_QUEUE *event_queue = NULL;
void event_queue_init();
void event_queue_destroy();
Looks like those structures are defined in a header file. Then they’re
#includedinto multiple translation units. You need to make it such that there’s only one definition of the particular item.Given that these are global variables, the way you generally do that is declaring them by marking them
externin the header, and then defining them in some translation unit.