#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Sertaozinho-SP
    Posts
    45
    Rep Power
    11

    Smile error LNK2001: unresolved external symbol "public: __thiscall CComplex::~CComplex(voi


    Hi,

    I am a beginner C++ programmer. I bought C++ How to Program that comes with a version of Visual C++ 6.0 Introductory Edition, so that is what I am using now.

    I have two classes:

    CComplex -> Deals with complex numbers
    DFT -> Implements The Discrete Fourier Transform of Dicrete Function

    I am able to compile each class file (CComplex.cpp and Transforms.cpp and the main program CalculoDFT.class). However I receive the following errors when I try to build the project:

    Linking...
    Transforms.obj : error LNK2001: unresolved external symbol "public: __thiscall CComplex::~CComplex(void)" (??1CComplex@@QAE@XZ)
    CalculoDFT.obj : error LNK2001: unresolved external symbol "public: __thiscall CComplex::~CComplex(void)" (??1CComplex@@QAE@XZ)
    Transforms.obj : error LNK2001: unresolved external symbol "public: void __thiscall CComplex::setComplexCart(double *,double *)" (?setComplexCart@CComplex@@QAEXPAN0@Z)
    CalculoDFT.obj : error LNK2001: unresolved external symbol "public: void __thiscall CComplex::setComplexCart(double *,double *)" (?setComplexCart@CComplex@@QAEXPAN0@Z)
    Transforms.obj : error LNK2001: unresolved external symbol "public: __thiscall CComplex::CComplex(void)" (??0CComplex@@QAE@XZ)
    CalculoDFT.obj : error LNK2001: unresolved external symbol "public: __thiscall CComplex::CComplex(void)" (??0CComplex@@QAE@XZ)
    CalculoDFT.obj : error LNK2001: unresolved external symbol "public: double __thiscall CComplex::moduloComplex(class CComplex)" (?moduloComplex@CComplex@@QAENV1@@Z)
    Debug/Transforms.exe : fatal error LNK1120: 4 unresolved externals
    Error executing link.exe.

    I apologize for the trouble anyway but will thank and appreaciate a lot any form of help!

    Thanks a lot!
    Daniel


    --------------------------------
    CComplex Class Header
    --------------------------------
    #ifndef CCOMPLEX_H
    #define CCOMPLEX_H

    class CComplex {
    public:

    CComplex();//contrutor

    ~CComplex();//destrutor

    //inicializa número complexo Cartesiano
    void setComplexCart(double *, double *);

    //inicializa número complexo Polar
    void setComplexPolar(double *, double *);

    //Acessores
    double getX( CComplex );
    double getY( CComplex );

    //converte um número complexo para coordenadas polares
    void C2P( CComplex );

    //converte um número complexo para coordenadas cartesianas
    CComplex P2C( double, double );

    //retorna o módulo de um número complexo
    double moduloComplex( CComplex );

    //retorna argumento de um numero complexo angulo entre coord x e y
    double argumentoComplex( CComplex );


    //imprime na tela um n.o complexo
    void printComplex( CComplex );


    //raio*(cos(teta)+j*sen(teta))
    double raio;
    double argumento;

    // ax +b
    double a;
    double b;

    };
    #endif
    ---------------------------------
    CComplex Implementation
    ---------------------------------
    #include <iostream>

    using std::cout;

    #include <cmath>

    #include "CComplex.h"

    //-------------------------------------------
    CComplex::CComplex(){
    cout << "instance of the complex class created!";
    cout << "/n";
    }
    //-------------------------------------------
    CComplex::~CComplex(){
    }
    //-------------------------------------------

    double getX(CComplex c){
    double aux = c.a;
    return aux;
    }
    double getY(CComplex c){
    double aux = c.b;
    return aux;
    }

    //-------------------------------------------
    void CComplex::setComplexCart(double * x, double * y) {
    a = *x;
    b = *y;
    }
    //-------------------------------------------
    void CComplex::setComplexPolar(double * radio, double * angulo){
    raio = *radio;
    argumento = *angulo;
    }
    //-------------------------------------------
    double CComplex::moduloComplex(CComplex c){
    return sqrt(pow(c.a,2)+pow(c.b,2));
    }
    //-------------------------------------------
    double CComplex::argumentoComplex(CComplex c){
    return atan((c.a/c.b));
    }
    //-------------------------------------------
    void CComplex::C2P(CComplex c){
    argumento = argumentoComplex(c);
    raio = moduloComplex(c);
    }
    //-------------------------------------------
    CComplex CComplex::P2C(double radio, double angulo){

    double jaca1;
    double jaca2;
    double r = radio;
    double ang = angulo;

    jaca1 = r*cos(ang);
    jaca2 = r*sin(ang);
    CComplex d;
    d.setComplexCart(&jaca1,&jaca2);
    return d;
    }
    //-------------------------------------------
    void CComplex::printComplex(CComplex c){
    cout << c.a << " + j*" << c.b << "\n";
    }
    ---------------------------------
    Transforms Header File
    ---------------------------------
    #ifndef TRANSFORMS_H
    #define TRANSFORMS_H



    #include "..\..\..\..\WORK\DANIEL\C++\EX11\CComplex.h" // Added by ClassView
    class Transforms
    {
    public:
    CComplex DFT(double fn[],int , int );
    Transforms();
    virtual ~Transforms();

    };

    #endif //
    ---------------------------------
    Transforms.cpp Implementation
    ---------------------------------
    /////////////////////////////////////////////////////////////////////
    //
    // Transforms.cpp: .
    //
    // Implementação da classe transforms
    //////////////////////////////////////////////////////////////////////

    #include <iostream>

    using std::cout;
    using std::cin;
    using std::endl;

    #include "Transforms.h"
    #include "..\..\..\..\WORK\DANIEL\C++\EX11\CComplex.h" // Added by ClassView
    #include <cmath>


    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////

    Transforms::Transforms()
    {

    }

    Transforms::~Transforms()
    {

    }

    //////////////////////////////////////////////////////////////////////
    // Funções membro da classe
    //////////////////////////////////////////////////////////////////////

    CComplex Transforms::DFT(double fn[], int k, int n)
    {
    int i;
    double aux1;
    double aux2;

    aux1 = 0;
    aux2 = 0;
    const double pi = 3.141;

    for(i = 0; i < n; i++){
    aux2 = fn[i]*sin(2*pi*k*i/n) + aux2;
    aux1 = fn[i]*cos(2*pi*k*i/n) + aux1;
    };

    CComplex d;
    aux1 = sqrt(n)*aux1;
    aux2 = -sqrt(n)*aux2;
    d.setComplexCart(&aux1,&aux2);

    return d;

    }
    ----------------------------------
    Main Program CalculoDFT.cpp
    ----------------------------------
    #include <iostream>

    using std::cout;
    using std::cin;
    using std::endl;

    #include ".\Transforms.h"
    #include "..\..\..\..\WORK\DANIEL\C++\EX11\CComplex.h" // Added by ClassView


    ///////////////////////////////////////////////////////////////
    //Programa principal
    ///////////////////////////////////////////////////////////////
    int main () {

    int N;
    int j;
    const int FunctionDim = 10;
    double Function[FunctionDim];

    cout << "Type the number of values of the function: " << endl;
    cin >> N;

    for(j=0;j<N;j++){

    cout << "type the value of f" << j << endl;
    cin >> Function[j];
    cout << endl;

    };

    Transforms t;
    CComplex c;
    double FunctionABSValues[FunctionDim];

    for(j=0;j<N;j++){

    c.setComplexCart(0,0);
    c = (t.DFT(Function,j,N));
    FunctionABSValues[j] = c.moduloComplex(c);
    };

    for(j=0;j<N;j++){
    cout << FunctionABSValues[j] << endl;
    };

    return 0;
    }//end
  2. #2
  3. No Profile Picture
    Dinesh_P_V
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    India
    Posts
    259
    Rep Power
    0

    Re: error LNK2001: unresolved external symbol "public: __thiscall CComplex::~CComplex


    Hope this might help you.

    http://mailman.mit.edu/pipermail/galib/2000-June/000258.html
    -Murugesan
    Last edited by murugesan; September 5th, 2003 at 01:21 AM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Sertaozinho-SP
    Posts
    45
    Rep Power
    11
    Hey,

    I could not solve the trouble. I only have two classes CComplex and Transforms. Apparently I am not getting to link all these classes to the main cpp program. Although this main program complies with no errors.

    thanks!
    Daniel
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Sertaozinho-SP
    Posts
    45
    Rep Power
    11
    Hi again,
    I just want to say I am no expert in C++, so things I am asking could sound too simple.

    I got to link everything by putting all my classes in a single directory. My includes
    declarations were simple "classname.h". This looks like the same trouble I had to understand packages in Java. It took me a while to understand it well.
    Heh, now I get a run time error, but that is with me to find out my mistake! At least now I know who made the error :-)

    thanks!
    Daniel

IMN logo majestic logo threadwatch logo seochat tools logo