I have problem with LNK2001: unresolved external symbol error. It shows only when I have all my classes in my namespace and refers to global variables which I use multiple files. Here is example code how my codes look like:
Engine.h
#pragma once
namespace Engine{
#include "Core.h"
#include "Display.h"
#include "Box.h"
// ... some code...
}
using namespace Engine;
Core.cpp
#include "Engine.h"
// ...some code...
Core.h
extern Matrix matrix;
// ... some code...
Display.cpp
#include "Engine.h"
Matrix matrix;
// ... some code...
Display.h
// ... some code...
Box.cpp
void Box::draw(PxShape *shape){
// matrix=.. some code...
}
Box.h
// ... some code...
Error message
1>Box.obj : error LNK2001: unresolved external symbol "struct Engine::Matrix Engine::matrix" (?matrix@Engine@@3UMatrix@1@A)
When I comment namespace everything works as it should. It is the first time when I want use a namespaces and I have no idea what to do with this.
Engine
if in the same header file that defines this namespace, you introduce all elements of theEngine
namespace into the global namespace. – Oswald Jul 6 '13 at 17:27