2

I am trying to port some 2005 project to a recent 2017 version and I am now facing a linking error. I have already linked the .lib files to the project.

The error says

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "struct auMatrix::Matrix<4,4,float> __cdecl auMatrix::operator*<4,4,4,float>(struct auMatrix::Matrix<4,4,float> const &,struct auMatrix::Matrix<4,4,float> const &)" (??$?D$03$03$03M@auMatrix@@YA?AU?$Matrix@$03$03M@0@ABU10@0@Z) referenced in function "bool __cdecl auIntersect::sphereVsPolygon(struct auVector::Vector3T<float> const &,float,struct auVector::Vector3T<float> const *,int,int,struct auGeom::TPlane const &,struct auVector::Vector3T<float> *,struct auVector::Vector3T<float> *,float *)" (?sphereVsPolygon@auIntersect@@YA_NABU?$Vector3T@M@auVector@@MPBU23@HHABUTPlane@auGeom@@PAU23@3PAM@Z) flRenderServer  D:\Projects\FLProject\RenderBox\singlegame_renderbox\Production\FantasticLeague\_Code\FLeague\flRenderServer\auGeom.lib(Intersect.obj)  1 

the problem is that I can't find the operator that is being described in the function it is mentioning. I'll paste the lengthy code here

bool auIntersect::sphereVsPolygon(Vector3 const &centro , float radio , Vector3 const *v , 
                                const int nVertices , int stride , TPlane const &p, Vector3 *pos /* = NULL  */, 
                                Vector3 *normal /* = NULL  */, float *overlap /* = NULL  */)
{
    ASSERT(nVertices>=3);

    //---------------------------------------------------------------------
    // Comprobamos si el primer vertice pertenece a la esfera, esto ES NECESARIO para que la 
    // rutina no falle con esferas que contengan totalmente al polígono
    Vector3 punto      = centro - *v;
    float  rad_cuad   = radio * radio;
    float  p_mod_cuad = punto.lengthSqr();
    if(p_mod_cuad <= rad_cuad)  
    {
        // El primer vértice del polígono pertenece a la esfera
        if(pos && normal && overlap)
        {
            // Esto es muy aproximado !!!!!!!!!!!!!!!!!!!!!!!
            *pos     = *v;
            *overlap = (float)sqrt(rad_cuad) - (float)sqrt(p_mod_cuad);
            //TPlano  normalPlane;
            //normalPlane.Create(*(v), *(v + stride*1), *(v + stride*2));
            //*normal  = (Vector3)(normalPlane);
            *normal = p.getNormal();
        }
        return true;
    }

    //---------------------------------------------------------------------
    // Calculamos el plano que contiene al poligono
    TPlane plano;
    //plano.Create(*(v), *(v + stride*1), *(v + stride*2));
    plano = p;

    //---------------------------------------------------------------------
    // Calculamos la distancia desde el centro de la esfera hasta el plano
    float dist      = plano.dist(centro);
    float fabs_dist = (float)fabs(dist);
    if(fabs_dist < radio)
    {
        //---------------------------------------------------------------------
        // La esfera toca el plano del polígono, comprobamos si toca el polígono

        // Calculamos la proyección del centro de la esfera sobre el plano
        float  labda     = plano.w - plano.getNormal() * centro;
        Vector3 proy_cent = centro  + plano.getNormal() * labda;
        ASSERT(fabs(plano.dist(proy_cent)) < 0.001f);

        // Comprobamos si la proyección del centro de la esfera sobre el plano 
        // pertenece al polígono, para ello proyectamos todo sobre el plano de 
        // coordenadas que mas perpendicular sea a la normal del plano
        float fabs_planox = (float)fabs(plano.x);
        float fabs_planoy = (float)fabs(plano.y);
        float fabs_planoz = (float)fabs(plano.z);
        float p_x  , p_y;
        int   ind_x, ind_y;
        if(fabs_planox > fabs_planoy)
        {
            if(fabs_planox > fabs_planoz)
            {
                // Proyectamos sobre el plano YZ
                ind_x = 1;
                ind_y = 2;
            }
            else
            {
                // Proyectamos sobre el plano XY
                ind_x = 0;
                ind_y = 1;
            }
        }
        else
        {
            if(fabs_planoz > fabs_planoy)
            {
                // Proyectamos sobre el plano XY
                ind_x = 0;
                ind_y = 1;
            }
            else
            {
                // Proyectamos sobre el plano XZ
                ind_x = 0;
                ind_y = 2;
            }
        }
        p_x = proy_cent[ind_x];
        p_y = proy_cent[ind_y];
        // Comprobamos si el centro está al lado correcto de todas las aristas
        int   j      = nVertices - 1;
        bool  dentro = true;
        float signo;
        for(int i=0; i<nVertices; j=i, i++)
        {
            // Calculamos la recta en la forma:  N*p - D = 0
            float NX =    (*(v + stride*i)).operator[](ind_y) -    (*(v + stride*j)).operator[](ind_y);
            float NY =  - (*(v + stride*i)).operator[](ind_x) -    (*(v + stride*j)).operator[](ind_x);
            float D  = NX*(*(v + stride*i)).operator[](ind_x) + NY*(*(v + stride*i)).operator[](ind_y);
            // Metemos el punto en la ecuación
            float s = (NX*p_x + NY*p_y - D)>0 ? 1.0f : -1.0f;
            if(!i) 
                // Primer signo
                signo = s;
            else
                // Comprobamos que el nuevo signo sea = que los anteriores
                if(s!=signo)    
                {
                    dentro = false;
                    break;
                }
        }
        if(dentro) 
        {
            // Efectivamente, la proyección del centro de la esfera pertenece al polígono
            if(pos && normal && overlap)
            {
                // Esto es muy aprox !!!!!!!!!!!!!!!!!!!!!!!
                *overlap = radio - fabs_dist;
                *pos     = proy_cent;
                //TPlano  normalPlane;
                //normalPlane.Create(*(v), *(v + stride*1), *(v + stride*2));
                //*normal  = (Vector3)(normalPlane);
                *normal = p.getNormal();
            }
            return true;
        }
        // Comprobamos si la esfera colisiona con el segmento de cada lado
        j = nVertices - 1;
        for(int i = 0;i < nVertices; j=i, i++)
        {
            // Calculamos las intersecciones de la esfera con la recta que contiene al polígono
            Vector3 vrecta      = Vector3((*(v + stride*i)).x - (*(v + stride*j)).x, (*(v + stride*i)).y 
                                      - (*(v + stride*j)).y, (*(v + stride*i)).z - (*(v + stride*j)).z);
            float  vrecta_cuad = vrecta * vrecta;
            if(vrecta_cuad > 1.0e-6)
            {
                // Desplazamos la esfera para que la recta pase por el origen
                Vector3 n_centro             = centro - * (v + stride*j);
                float  vrecta_por_centro = vrecta * n_centro;
                float  discri            = vrecta_por_centro * vrecta_por_centro - vrecta_cuad*(n_centro*n_centro-rad_cuad);
                if(discri > 0)
                {
                        discri       = (float)sqrt(discri);
                        float denom  = vrecta_cuad;
                        float labda1 = (vrecta_por_centro + discri) / denom;
                        float labda2 = (vrecta_por_centro - discri) / denom;
                        if(inRange(labda1,0.0f,1.0f) || inRange(labda2,0.0f,1.0f)) 
                        {
                            // La esfera colisiona con este lado
                            if(pos && normal && overlap)
                            {
                                // Esto es muy aprox !!!!!!!!!!!!!!!!!!!!!!!
                                float labda         = (labda1 + labda2) * 0.5f;
                                *pos                = *(v + stride*j)   + vrecta * labda;
                                Vector3 centro_inter = *pos              - centro;
                                *overlap            = radio             - centro_inter.length();
                                //TPlano  normalPlane;
                                //normalPlane.Create(*(v), *(v + stride*1), *(v + stride*2));
                                //*normal  = (Vector3)(normalPlane);
                                *normal = p.getNormal();
                            }
                            return true;
                        }
                }
            }
        }
    }

    return false;
}

I checked if the files are included. Matrix4 * is inside Matrix.h and Intersect.h does include Matrix.h.

Any help would be appreciated :)

Thanks

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
Skiggz
  • 49
  • 1
  • 4
  • When resolving linking errors, you should present all "include" statements and files involved. Obviously "unresolved external symbol" is mentioned in one of them. – SChepurin Aug 20 '20 at 07:30
  • @SChepurin yes, it has Matrix.h as #included headers in the file but still it's happening – Skiggz Aug 20 '20 at 08:45
  • The linking errors are difficult to resolve online, because it involves different include paths issues, several libraries linked in proper order, library missed and porting issues (dependencies). You really should try to read the source mentioned above to do it yourself. – SChepurin Aug 20 '20 at 09:51
  • 1
    @SChepurin, ah, I solved it. `*` operator was overloaded twice in the same namespace but different template params. – Skiggz Aug 20 '20 at 10:38

0 Answers0