0

Ok a little introduction into the issue: I'm working on a rendering engine(compiling in 32 bit mode) in C++/DirectX11 in Visual Studio 2012 running on Windows 7 - 64 bit OS and I have a strange link error that comes up in my Entity class (the Entity3D is like the basic actor of the scene).
All of my bounding volume classes inherit from a Shape3D class.Each Entity has a Shape3D* boundingVolume member in it, that is initialized to a specific shape type at initialization time.
When colliding between two Shape3D's I pass them trough a function - bool Intersect(Shape3D* a, Shape3D* b) the function then checks their types(Sphere/*Box*/Whatever) and the type represents a number which is the index of a function in an array of function pointers:

bool(*IntersectArray[4][4])(Shape3D* a, Shape3D* b) = 
{
    {
        IntersectSphereSphere,
        IntersectSphereBox,
        IntersectSphereOrientedBox,
        IntersectSphereFrustum,
    },
    {
        IntersectBoxSphere,
        IntersectBoxBox,
        IntersectBoxOrientedBox,
        IntersectBoxFrustum
    },
    {
        IntersectOrientedBoxSphere,
        IntersectOrientedBoxBox,
        IntersectOrientedBoxOrientedBox,
        IntersectOrientedBoxFrustum
    },
    {
        IntersectFrustumSphere,
        IntersectFrustumBox,
        IntersectFrustumOrientedBox,
        IntersectFrustumFrustum
    }
};

So it's like a virtual dispatch. Ok so the InersectArray is the array of the functions(declared in Intersect.h) and that's what gives me the link error:

error LNK1169: one or more multiply defined symbols found
error LNK2005: "char (__cdecl*(* Engine::Collision::IntersectArray)[4])(class Engine::Collision::Shape3D *,class Engine::Collision::Shape3D *)" (?IntersectArray@Collision@Engine@@3PAY03P6ADPAVShape3D@12@0@ZA) already defined in Entity3D.obj
File Intersect.obj

Intersect.h is only included in Entity3D.cpp, it's no included in Entity3D.h, nor in any of the headers that Entity3D.h includes.Entity3D.cpp only includes Entity3D.h and Intersect.h.I cleaned and rebuilt, error persists.Intersect(Shape3D a, Shape3D* b)* is called only in one method of Entity3D in the Entity3D.cpp file. There are no other compile errors or warnings currently in the project. What else could cause such an issue?

qehgt
  • 2,972
  • 1
  • 22
  • 36
ulak blade
  • 2,515
  • 5
  • 37
  • 81
  • 1
    You have a `#pragma once` or `#ifndef` on your header? Doesn't look like it should matter, but just double checking. – IdeaHat Mar 27 '13 at 20:45
  • yes every header file has both `#pragma once` and an `#ifndef` include guard – ulak blade Mar 27 '13 at 20:46
  • 1
    What is `Intersect.lib`? – Jesse Good Mar 27 '13 at 20:49
  • oh its a type error I meant `Intersect.obj` :( sorry it's basically `Intersect.cpp` – ulak blade Mar 27 '13 at 20:51
  • 2
    Well, the linker is arguing with your assumptions. It says that it is defined in Entity3D and also in Intersect. Also something wrong with your claim that it is in Entity. There just isn't much point in arguing with the linker, you'll lose, stop putting this definition in a .h file. Just move it to a .cpp file and be done with it. – Hans Passant Mar 27 '13 at 20:51
  • 1
    Your `Intersect.cpp` contains the symbol `IntersectArray`. – Jesse Good Mar 27 '13 at 20:56
  • ok, I moved the entire definition in the Intersect.cpp file, since for now I don't need it anywhere else in the project and the built was successful.Thanks for the help! – ulak blade Mar 27 '13 at 20:59

1 Answers1

0

Fixed the issue, I just moved the definition of IntersectArray in the Intersect.cpp file, since for now that's the only place it's needed.

ulak blade
  • 2,515
  • 5
  • 37
  • 81