I have two header files:
DirectX_Engine.h
#pragma once
#include "Main.h"
#include <d3d9.h>
and:
Main.h
#pragma once
#include <Windows.h>
#include "DirectX_Engine.h"
int imRunning = 1;
After compiling, I get the following linker errors:
error LNK1169: one or more multiply defined symbols found
error LNK2005: "int imRunning" (?imRunning@@3HA) already defined in DirectX_Engine.obj
I’m also getting a ‘file is not found or directory doesn’t exist error’ when #includeing “d3dx9.h”. Any idea?
Two ideas. Firstly, you are including
DirectX_Engine.hinMain.handMain.hinDirectX_Engine.h. This will obviously not work.Secondly,
int imRunninggets included to each .cpp file that includesMain.hand the compiler treats it as a definition. Then the linker comes and seesimRunningdefined in each of these files and doesn’t know what to do. The solution is using extern:In
Main.h:In one of the .cpp files: