none
LNK2019 unresolved external symbol error

    Question

  • Hey everyone. Im creating a program that inputs polygon data and outputs polygon projections. When compiling some code I get the following build output.

    ------ Build started: Project: projection, Configuration: Debug Win32 ------

    Compiling...

    homework6.cpp

    Linking...

    projection.obj : error LNK2019: unresolved external symbol "class vector<double> __cdecl operator*(class vector<double> &,class vector<double> &)" (??D@YA?AV?$vector@N@@AAV0@0@Z) referenced in function "void __cdecl parallel(void)" (?parallel@@YAXXZ)

    projection.obj : error LNK2019: unresolved external symbol "class vector<double> __cdecl operator*(class vector<double> &,double)" (??D@YA?AV?$vector@N@@AAV0@N@Z) referenced in function "void __cdecl parallel(void)" (?parallel@@YAXXZ)

    C:\Documents and Settings\Flame\My Documents\Visual Studio 2005\Projects\projection\Debug\projection.exe : fatal error LNK1120: 2 unresolved externals

    Build log was saved at "file://c:\Documents and Settings\Flame\My Documents\Visual Studio 2005\Projects\projection\projection\Debug\BuildLog.htm"

    projection - 3 error(s), 0 warning(s)

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Im using a custom built data structure to hold my vertices called "vector" The problem arises when attempting to do vector cross products in my line:

    Ry = Rz * Rx;

    Where Ry, Rz, and Rx are all of datatype vector<double>. The code for calculating the cross product is this:

    template <class ElType>

    vector<ElType> operator*(vector<ElType>& a, vector<ElType>& b)

    {

    assert(a.len == b.len);

    vector<ElType> ans(.len);

    ans[0] = a[1]*b[2] - a[2]*b[1];

    ans[1] = a[2]*b[0] - a[0]*b[2];

    ans[2] = a[0]*b[1] - a[1]*b[0];

    return ans;

    }

    The code is intended to assign vector Rz to vector a and vector Rx to vector b for calculation. Not sure if this will help at all but here is my vector class definition as well:

    class vector

    {

    friend class matrix<ElType>;

    ElType * data;

    int len;

    public:

    int length()const;

    vector();

    vector(int n);

    ~vector(){ delete [] data;}

    //Copy operator

    vector(const vector<ElType>& v) ;

    //assignment operator

    vector<ElType>& operator =(const vector<ElType> &original);

    ElType& operator[](int i)const ;

    void zero();

    vector<ElType> operator+(const vector<ElType>& v);

    vector<ElType> operator-(const vector<ElType>&v);

    void rprint()const; //print entries on a single line

    void resize(int n);

    void homog();

    void remap();

    double magnitude();

    int operator==(const vector<ElType>& v)const;

    friend vector<ElType> operator*(ElType c,vector<ElType>& v );

    friend vector<ElType> operator*(vector<ElType>& v,ElType c );

    friend vector<ElType> operator*(vector<ElType>& a, vector<ElType>& b);//My problem function

    //friend ostream &operator<<(ostream& s,vector<ElType>& v);

    };

    So does anyone have any idea what is going on here? Id greatly appreciate any help. Thanks!

    Tuesday, November 07, 2006 10:53 PM

Answers

  • Did you put the implementation in a class or a namespace? It should be in the global namespace.

    --
    SvenC

    Wednesday, November 08, 2006 5:44 AM

All replies

  • Where did you implement 

    template <class ElType> vector<ElType> operator*(vector<ElType>& a, vector<ElType>& b)

    Is that file in the project, so that it gets build?

    --
    SvenC

    Tuesday, November 07, 2006 11:08 PM
  • Its implemented in a header file that is linked to the source/project. So yes, its in the project and gets built.
    Tuesday, November 07, 2006 11:25 PM
  • Are you sure?  Can you paste this implementation in your reply?
    Wednesday, November 08, 2006 2:23 AM
  • Absolutely sure - when commenting out my lines using the cross product function it runs fine (I have to use the header file for vector/matrix addition as well as the type definition of 'vector' and 'matrix')

    but heres the top of my .cpp file:

    #include <iostream>

    #include <gl/glut.h>

    #include <windows.h>

    #include <vector>

    #include "matrix.h"

    #define HOMOG 4

     

    so the header file is called matrix.h - and is in the same folder as the .cpp file (which explains the use of the quotes)

    I guess my problem is harder than I thought?

    Wednesday, November 08, 2006 2:36 AM
  • Did you put the implementation in a class or a namespace? It should be in the global namespace.

    --
    SvenC

    Wednesday, November 08, 2006 5:44 AM
  • Not sure what you mean by that - but I ended up using a workaround for it. I think the problem was tied to an overloading of the * operator which was dependent upon what the vector was paired with for multiplication.

     

    Anyways - I appreciate the help guys. Ill just consider it resolved.

    Wednesday, November 08, 2006 5:49 AM