load関数とpraph関数で共通して使うファイルをdefine.hというファイルにまとめてかいて、それぞれのファイルでインクルードしたのですが、2重エラーが起きました。define.hをインクルードガードしましたが治りません。
エラーとソースは以下になります。
エラー
load.obj : error LNK2005: "int * img_player" (?img_player@@3PAHA) は既に graph.obj で定義されています。
1>C:\i2-hougyoku\isekai-h\Debug\isekai-h.exe : fatal error LNK1169: 1 つ以上の複数回定義されているシンボルが見つかりました。
ソース
//define.h
#ifndef INCLUDED_DEFINE
#define INCLUDED_DEFINE
//描画だの被るやつの定義用
#include "../include/DxLib.h";
int img_player[12]; //今回playerはエナのみなので1つだけ 正面、→、←でそれぞれアニメーション4枚ずつ、計12枚
#endif
#pragma once
#include "../include/DxLib.h";
//構造体とかのやつ
//キャラクターに関する構造体
typedef struct{
int flag; //フラグ
int cnt; //カウンタ
int power; //パワー
int point; //ポイント
int score; //スコア
int num; //残機数
int mutekicnt; //無敵状態とカウント
int img; //画像
int slow; //スローかどうか
double x,y; //座標
}player_st;
//構造体を使うための宣言
player_st player;
#endif
//ヘッダファイルどんどん追加する
#include "../include/DxLib.h";
#include "key.h";
#include "load.h";
#include "graph.h";
#include "../include/DxLib.h";
#include "define.h";
//ロード関数形書き込み
char* imgPlayer="../dat/img/char/player.png"; //playerファイル名
void load(){
//自機画像読み込み
LoadDivGraph(imgPlayer,12,4,3,73,73,img_player) ;
//敵画像読み込み
//弾画像読み込み
}
//graph.cpp
#include "define.h";
#include "struct.h";
void graphPlayer(){
DrawRotaGraphF(player.x,player.y,1.0,0.0,img_player[0],TRUE);
}
void graphMain(){
graphPlayer();
}
#include "include.h"
//ループで必ず行う3大処理
int ProcessLoop(){
if(ProcessMessage()!=0)return -1;//プロセス処理がエラーなら-1を返す
if(ClearDrawScreen()!=0)return -1;//画面クリア処理がエラーなら-1を返す
GetHitKeyStateAll_2();//現在のキー入力処理を行う
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
ChangeWindowMode(TRUE);//ウィンドウモード
if(DxLib_Init() == -1 || SetDrawScreen( DX_SCREEN_BACK )!=0) return -1;//初期化と裏画面化
int page = 0;
//ロード
load();
while(ProcessLoop()==0&&CheckStateKey(KEY_INPUT_ESCAPE)==0){//メインループ
graphMain();
ScreenFlip();//裏画面反映
}
DxLib_End();//DXライブラリ終了処理
return 0;
}
エラーの原因は2重インクルードしているdefine.hだと思いますが、プログラム内で参照しているファイルもすべて書きました。
見辛いかもしれませんが、よろしくお願いします。