Error communicating Static Lib with multiple definitions

So, I'm trying to create a small 3D engine as an exercise in VC ++ 8.0. I have a MathLib static library and Render static lib linked to my exe testBed. Right now, Render has two classes: Color and DXManager3D. The color includes my Vector.h from MathLib just fine, no problem.

The second I try to include Vector.h in DXManager3D, it blows me up, saying that the character is defined twice, and the second definition is ignored (warning from lib). I thought that perhaps this caused it twice as well, since the test I removed Vector.h from Color.h and left it in DXManager3D.h - the same problem. I checked the triple to make sure that I have everything included in the ifndef to protect against this, so that I left scratches on my head.

DXManager3D.obj: warning LNK4006: "public: __thiscall Math :: Vector :: Vector (void)" (? 0Vector @Math @@ QAE @XZ), already defined in Render.obj; second definition is ignored

What really bothers me is that when I create a separate Render.lib from TestBed that should not link anything since it is a static library, right? I still get multiple character warnings. If I create an instance of DXManager3D basically, my warnings become errors.

Render.lib (DXManager3D.obj): LNK2005 error: "public: __thiscall Math :: Vector :: Vector (void)" (? 0Vector @Math @@ QAE @XZ) already defined in WinMain.obj

Yes, I have F1'd LNK4006 and LNK2005, and MSDN solutions do not work for me. Sorry, if this question was asked before, I could not find anything solid to help me use the search function.

Thank!

0
c ++ linker-errors
Apr 04 '09 at 19:12
source share
2 answers

Is your Vector ctor defined in the header outside the class definition? Make it inline and then change

 class Vector { public: Vector(); // ... }; Vector::Vector() { // ... } 

to

 class Vector { public: Vector() {} // ... }; 

or use the explicit inline qualification:

 class Vector { public: Vector(); // ... }; inline Vector::Vector() { // ... } 
+2
Apr 04 '09 at 19:19
source share

It looks like you have a communication problem with your vector class. Based on your information, it seems that the class is bound in any lib that includes the header file. This is an internal connection, and you really need an external connection.

Can you host the contents of Vector.h, or at least the Vector () constructor? This should give us the key to what is actually happening.

Communication: http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/cplr020.htm

EDIT

Based on your comment, it seems that you have declared all the functions in the header file outside the class library. You should put them in a file without a header (for example, the Vector.cpp file).

This will give your program the appropriate binding, and you can include Vector.h in both programs.

+1
Apr 04 '09 at 19:17
source share



All Articles