0

So I have a LNK2019 error on the constructor and destructor of the class Classifier. The error also exists on the method classify. As you will see, they are defined in the .cpp file. What am I overlooking?

Here are the 3 errors: neutropenia_main.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl Classifier::Classifier(class QObject *)" (??0Classifier@@QEAA@PEAVQObject@@@Z) referenced in function "private: void __cdecl Neutropenia_Main::on_TS_Classifier_clicked(void)" (?on_TS_Classifier_clicked@Neutropenia_Main@@AEAAXXZ)

neutropenia_main.obj:-1: error: LNK2019: unresolved external symbol "public: virtual __cdecl Classifier::~Classifier(void)" (??1Classifier@@UEAA@XZ) referenced in function "private: void __cdecl Neutropenia_Main::on_TS_Classifier_clicked(void)" (?on_TS_Classifier_clicked@Neutropenia_Main@@AEAAXXZ)

neutropenia_main.obj:-1: error: LNK2019: unresolved external symbol "public: void __cdecl Classifier::classify(class std::vector >,class patient_data)" (?classify@Classifier@@QEAAXV?$vector@Vpatient_data@@V?$allocator@Vpatient_data@@@std@@@std@@Vpatient_data@@@Z) referenced in function "private: void __cdecl Neutropenia_Main::on_TS_Classifier_clicked(void)" (?on_TS_Classifier_clicked@Neutropenia_Main@@AEAAXXZ)

Here is the use of the class Classifier.

#include "neutropenia_main.h"
#include "ui_neutropenia_main.h"
#include "QObject"
#include "xlsxdocument.h"
#include "xlsxworksheet.h"
#include "xlsxworkbook.h"
#include "QtCore"
#include "xlsxcell.h"
#include "xlsxcellrange.h"
#include "xlsxcellreference.h"
#include "patient_data.h"
#include <vector>
#include <stdlib.h>
#include "classifier.h"
#include <QWidget>

void Neutropenia_Main::on_TS_Classifier_clicked()
{
    int bottomrow = BottomLeft.row();
    ui ->Classification_Table->setRowCount(bottomrow);
    ui ->Classification_Table->setColumnCount(3);

    Classifier cl;

    QStringList headers;
    headers << "Patient Number" << "Classification" << "Actual";

    int i = 0;

    QVariant Case;
    QVariant Classified;
    QVariant Actual;

    for (auto current: patients)
    {
        if (current.getValid())
        {    cl.classify(patients,current);
             Case = current.getCaseNumber();
            ui -> Classification_Table -> setItem(i,0,new QTableWidgetItem(Case.toString()));
            ui -> Classification_Table -> setItem(i,2,new QTableWidgetItem(current.stringNeut(current.getNeut())));
            if (cl.CurrentvsNeutropenic.SD[0] < cl.CurrentvsNonNeutropenic.SD[0])
            {
                ui -> Classification_Table ->setItem(i,1,new QTableWidgetItem("Yes"));
                 Classified = "Yes";
            }else if (cl.CurrentvsNonNeutropenic.SD[0] > cl.CurrentvsNonNeutropenic.SD[0])
            {
                ui -> Classification_Table -> setItem(i,1,new QTableWidgetItem("No"));
                 Classified = "No";
            }else{
                 Classified = "Same SD";
                ui -> Classification_Table -> setItem (i,1,new QTableWidgetItem("Same SD"));
            }
        }
        classifiedpatients temp;
        temp.Case = Case;
        temp.Classifed = Classified;
        temp.Actual = current.stringNeut(current.getNeut());

        classified.push_back(temp);
    }
}

Here is the .h file of Classifier
#ifndef CLASSIFIER_H
#define CLASSIFIER_H

#include "patient_data.h"
#include <QObject>
#include <vector>
#include <stdlib.h>

class Classifier : public QObject
{
    Q_OBJECT
public:
    explicit Classifier(QObject *parent = 0);
    ~Classifier();
    void classify(std::vector<patient_data>data, patient_data i);


    struct CreateSDTable
    {
        std::vector<int>sum[3];   //element 0 = Tumor, element 1 = Stage, element 2 = Adjuvant
        std::vector<long>mean[3];
        std::vector<long>error[3];
        std::vector<long>SDL[3];
        std::vector<long>SD[3];
    };

    CreateSDTable CurrentvsNeutropenic;
    CreateSDTable CurrentvsNonNeutropenic;

private:

    std::vector<int> calculatesums(std::vector<patient_data> data, patient_data i);
    std::vector<long> calculatemean(std::vector<int>validpatients, CreateSDTable Neut, CreateSDTable NonNeut);
    std::vector<long>calculateerror(patient_data d, std::vector<int>m);
    std::vector<long>calculatSDL(int nvp, CreateSDTable CVN, CreateSDTable CVsNN);
    int NumofValidPatients(patient_data x);

    //void classify(std::vector<patient_data>data, patient_data i);

signals:

public slots:

};

#endif // CLASSIFIER_H

#include "classifier.h"
#include "patient_data.h"
#include <vector>
#include <stdlib.h>
#include <math.h>


Classifier::Classifier(QObject *parent) :
    QObject(parent)
{
}

void Classifier::classify(vector<patient_data> data, patient_data i)
{
    int numvalidpatients = NumofValidPatients(data);

    if (i.getvalid())
    {
        Neutropenic N;

        std::vector<long>temp = sums(data,i, N);
        while (j < 3){CurrentvsNonNeutropenic.sum[j] = temp[j];}
        while(j > 3){CurrentvsNeutropenic.sum[j] = temp[j+3];}

        temp = calculatemean(numvalidpatients,CurrentvsNeutropenic,CurrentvsNonNeutropenic);
        while (j < 3){CurrentvsNonNeutropenic.mean[j] = temp[j];}
        while(j > 3){CurrentvsNeutropenic.mean[j] = temp[j+3];}

        temp = calculateerror(data,mean);
        while (j < 3){CurrentvsNonNeutropenic.error[j] = temp[j];}
        while(j > 3){CurrentvsNeutropenic.error[j] = temp[j+3];}

        temp = calculateSDL(numvalidpatients,CurrentvsNeutropenic,CurrentvsNonNeutropenic);
        while (j < 3){CurrentvsNonNeutropenic.SDL[j] = temp[j];}
        while(j > 3){CurrentvsNeutropenic.SDL[j] = temp[j+3];}
    }
}
user3255175
  • 67
  • 1
  • 5
  • Does your main.cpp file `#include "classifier.h" ` ? because the link error makes it sound like main does NOT include the classifier.h file. – StarPilot Dec 05 '14 at 22:06
  • I added my #includes for main. main does include classifier.h – user3255175 Dec 05 '14 at 22:32
  • 2
    did you add `classifier.cpp` file to the project set? That is, is it being compiled to an `obj` file? You have your main.cpp file being compiled, but is classifier.cpp being compiled as well? – StarPilot Dec 05 '14 at 22:35
  • your right... i don't see a make file classifier, i will get back to you – user3255175 Dec 05 '14 at 23:12
  • how do you add a source code to a build, I thought it was automatic. I build a class before classifier, and I do not recall having to do anything extra to have that class built – user3255175 Dec 05 '14 at 23:14
  • [What is an undefined reference/unresolved external symbol error and how do I fix it?: Failure to link against appropriate libraries/object files or compile implementation files](http://stackoverflow.com/a/12574400/902497) – Raymond Chen Dec 06 '14 at 01:31

0 Answers0