こんにちは、私は現在 C++ でプログラムに取り組んでおり、私の IDE は明らかに VC++ であり、このリンカ エラーに遭遇しました。
error LNK2005: "class Graphics TheGraphics" (?TheGraphics@@3VGraphics@@A) already defined in Game.obj
修正方法を調べましたが、修正されたリンクはありませんでした。だから私はあなたにすべて自分自身に尋ねると思いました。これらはすべて私のファイルです
Game.h
Graphics.h
Inc.h
Main.h
Game.cpp
Graphics.cpp
Main.cpp
WndProc.cpp
そして、私が持っているすべてのヘッダーファイルに
#ifndef ...
#define...
..
#endif
また、ヘッダーファイルにいくつかのインクルードがあります。
Inc.h では、#ifndef と #define の間にこれがあります。
#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include "Game.h"
#include "Graphics.h"
Main.h では、#ifndef と #define の間にこれがあります
#include "Inc.h"
また、オブジェクトのゲームおよびグラフィックス オブジェクトも作成しました。
extern Game TheGame;
extern Graphics TheGraphics
私も1つの関数を宣言しました
LRESULT CALLBACK WndProc(HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam);
それが Main.h です
Game.h と Graphics.h では、#ifndef と #define の前にこれを持っています
#include "Main.h"
Game.h では、Game というクラスと GAMESTATE という列挙型を作成しました。Graphics.h で、Graphics というクラスを作成しました。
クラスのすべての .cpp ファイルにはクラス ヘッダーのみが含まれ、WndProc には Main.h が含まれます。
結局、コンパイルするとこれが得られます。
1>Graphics.obj : error LNK2005: "class Graphics TheGraphics" (?TheGraphics@@3VGraphics@@A) already defined in Game.obj
1>Graphics.obj : error LNK2005: "class Game TheGame" (?TheGame@@3VGame@@A) already defined in Game.obj
1>Main.obj : error LNK2005: "class Graphics TheGraphics" (?TheGraphics@@3VGraphics@@A) already defined in Game.obj
1>Main.obj : error LNK2005: "class Game TheGame" (?TheGame@@3VGame@@A) already defined in Game.obj
1>WndProc.obj : error LNK2005: "class Graphics TheGraphics" (?TheGraphics@@3VGraphics@@A) already defined in Game.obj
1>WndProc.obj : error LNK2005: "class Game TheGame" (?TheGame@@3VGame@@A) already defined in Game.obj
1>F:\Games\Zombie Lypse\Release\Zombie Lypse.exe : fatal error LNK1169: one or more multiply defined symbols found
助けてください私はいたるところを見てきましたが、自分で修正しようとしました。まだ何もありません。