2011-10-19 112 views
0

得到这个我不知道这是什么(C++连接错误)

1>main_display.obj : error LNK2005: "struct ALLEGRO_DISPLAY * main_display" ([email protected]@[email protected]@A) already defined in event_queue.obj 
1>main.obj : error LNK2005: "struct ALLEGRO_DISPLAY * main_display" ([email protected]@[email protected]@A) already defined in event_queue.obj 
1>main.obj : error LNK2005: "struct ALLEGRO_TIMER * timer" ([email protected]@[email protected]@A) already defined in event_queue.obj 
1>main.obj : error LNK2005: "struct ALLEGRO_EVENT_QUEUE * event_queue" ([email protected]@[email protected]@A) already defined in event_queue.obj 
1>main_timer.obj : error LNK2005: "struct ALLEGRO_TIMER * timer" ([email protected]@[email protected]@A) already defined in event_queue.obj 

任何想法可能会导致此?

编辑:

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(); 
+0

我没有结构....和名称是免费的... – Vladp

回答

3

看起来像这些结构在一个头文件中定义。然后他们将#included分成多个翻译单元。你需要使它只有一个特定项目的定义。

鉴于这些是全局变量,通常这样做的方式是在头文件中标记它们extern,然后在某个翻译单元中定义它们。

+0

解决它! :) 感谢您的extern余数 – Vladp

0

我猜你没有使用inline声明将函数实现放入头(.h)文件。

由于头文件包含在多个源中,函数的主体被多次编译。链接器抱怨不止一次看到该功能。

0

它看起来像你在不同的文件中定义相同的struct

没有实际看到的文件,这是我们所据我得到...

相关问题