Overloaded Functions LNK2019

Started by
3 comments, last by liquidsharp 17 years, 7 months ago
I have a solution in .NET v7 with two projects, and I am trying to link to a file from one project to one in the other. Thus, I have added the project and everything compiles and links, until I try to access an overloaded operator in the other project. So, here is some code...trimmed to just show what I am talking about: EditorView Project: #include "..\Math Engine\vector3.h" // Vector3 class definition class Perspective { public: Perspective() : initialEyePos(0.0, 0.0, 20.0), initialLookDir(0.0, 0.0, 0.0), eyePos(), lookDir(), { // initialize camera's initial position eyePos = initialEyePos; lookDir = initialLookDir; } private: const Vector3 initialEyePos; const Vector3 initialLookDir; Vector3 eyePos; Vector3 lookDir; }; Math Engine Project: class Vector3 { public: Vector3& operator=(const Vector3 &); }; // end class Vector3 Now, of course I have all of the needed constructors and other parts needed in each class (like I said, they compile), but my problem arises when I write eyePos = initialEyePos. For instance, I can do: eyePos.set(...) with no problems. But, when I try to use any overloaded operators from the Vector3 class, I get this error: EditorView error LNK2019: unresolved external symbol "public: class Vector3 & __thiscall Vector3::operator=(class Vector3 const &)" (??4Vector3@@QAEAAV0@ABV0@@Z) referenced in function "public: __thiscall Perspective::Perspective(void)" (??0Perspective@@QAE@XZ) Is the fact that my Vector3 object file and Perspective object file are in different folders a problem? I really don't think that is the problem because if it was, I would think that Visual Studio would have taken care of all of that when I added the Math Engine project to the established solution. This problem has been bothering me for some time now and any help, or hint toward a solution would be greatly appreciated. Thanks in advance.
Advertisement
Did you actually write the operator?
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Yeah, of course. Both classes are complete and have been tested (and work fine independently). In fact, I have used the Vector3 class before in different applications. But now, when I try to use it like I have many times in the past, I get this problem. The only thing I can think that I have done different is that I have added Vector3 to a Math Engine project space, and I now just include that entire project in solutions of other applications (so, in the past I just had one project in my solution and I just added all of my files to that one project).
Quote:Original post by liquidsharp
I really don't think that is the problem because if it was, I would think that Visual Studio would have taken care of all of that when I added the Math Engine project to the established solution.


Well, there's the problem. Within a "solution", the "projects" are all independent. The object files from one project will not be linked with another's -- although I suspect there has to be a way to ask VS to declare a dependence.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Well, I have finally figured it out! I had alredy set the dependencies for each project (EditorView -> MathEngine) but, I had both projects configured as .exe files when I should have had the MathEngine configured as a .lib file.

So, for any of you reading this and having the same problems, configure one project as a static library (Configuration properties -> General -> Configuration type -> static library) and everything should work fine.

Thank you Fruny for your help.

This topic is closed to new replies.

Advertisement