0

Maybe this error is invoking because of my wrong include statements... Error messages:

mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall MatrixGetter::MatrixGetter(void)" (??0MatrixGetter@@QAE@XZ) referenced in function "private: void __thiscall MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked@MainWindow@@AAEXXZ)

mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: void __thiscall MatrixGetter::getCountries(void)" (?getCountries@MatrixGetter@@QAEXXZ) referenced in function "private: void __thiscall MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked@MainWindow@@AAEXXZ) 

debug\MdpProject.exe:-1: error: LNK1120: 2 unresolved externals

MdpProject.pro file

######################################################################
# Automatically generated by qmake (3.0) ?? ??? 27 01:48:55 2014
######################################################################

TEMPLATE = app
TARGET = MdpProject
INCLUDEPATH += .
QT += sql
# Input
HEADERS += dialog.h mainwindow.h matrixgetter.h matrixgetterdao.h
FORMS += dialog.ui mainwindow.ui
SOURCES += dialog.cpp \
           main.cpp \
           mainwindow.cpp \
           matrixgetter.cpp \
           matrixgetterdao.cpp

MainWindow.h class:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include "matrixgetter.h"

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
        Q_OBJECT


    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();

    private slots:
        void on_pushButton_clicked();

    private:
        Ui::MainWindow *ui;
    };

    #endif // MAINWINDOW_H

MainWindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "dialog.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->progressBar->setValue(100);

}

QString prop;
QString country;
MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{

    Dialog *d = new Dialog();
//    MatrixGetter* mgetter = new MatrixGetter();
//    mgetter->getCountries();
    d -> show();
}

If I uncomment these lines, all will be fine. MatrixGetter has one empty method getCountries():

MatrixGetter.h

#ifndef MATRIXGETTER_H
#define MATRIXGETTER_H
namespace Ui {
    class MatrixGetter;
}

class MatrixGetter
{
public:
    MatrixGetter();
    void getCountries();
};

#endif // MATRIXGETTER_H

MatrixGetter.cpp

#include "matrixgetter.h"


MatrixGetter::MatrixGetter()
{}

void MatrixGetter::getCountries(){}
Boris Mitioglov
  • 1,092
  • 4
  • 16
  • 32
  • There's no compiler throwing just plain error message numbers for errors. What does your error message say?? Isn't it clear enough for you? – πάντα ῥεῖ Mar 30 '14 at 20:37
  • What are these `QString prop;` and `QString country;`? Please show the exact error message. – vahancho Mar 30 '14 at 20:39
  • @goodspeed, do you compile your MatrixGetter.cpp file too? – vahancho Mar 30 '14 at 20:46
  • @vahancho I don't know, I just click on Build button in QT creator – Boris Mitioglov Mar 30 '14 at 20:50
  • 2
    @goodspeed If the `MatrixGetter.cpp` is not part of the project, then what do you expect? Make sure you've added it to the project. – Kuba hasn't forgotten Monica Mar 31 '14 at 00:19
  • @KubaOber I deleted all files from project directory except .h, .cpp and .pro files – Boris Mitioglov Apr 01 '14 at 17:31
  • 1
    I can't reproduce it on my end. Sorry. I've copy-pasted all of your code, including the .pro file, removed references to missing header files, added stubs for undefined classes, and it links just fine. Matrixgetter isn't your problem. – Kuba hasn't forgotten Monica Apr 01 '14 at 17:33
  • 1
    "I deleted all files from project directory except .h, .cpp and .pro files" That's not what I asked you to do. I've asked you to delete the **build directory**, in its entirety. The build directory is where the executable and generated files go, and is *not* the project directory. My bet is that once you do that and hit build again, everything will be fine. – Kuba hasn't forgotten Monica Apr 01 '14 at 17:34
  • @KubaOber I have 2 folders named "debug" and "release" under MdpProject, they are empty... I deleted them also but it doesn't help.. Oh, what I did wrong > – Boris Mitioglov Apr 01 '14 at 17:46
  • @goodspeed The build directory is available in Qt Creator by going to `Projects->Build&Run->Build tab`. Whatever directory you refer to is the wrong one, since it can't be empty after a build that failed at the link stage! Find the build directory, remove it **in its entirety**, and you'll be all set. – Kuba hasn't forgotten Monica Apr 01 '14 at 17:48
  • What you are doing wrong, so far, is panicking and not understanding the basic concepts used in the development tools that you're using. Shadow build and build directory are fundamental and you won't go far without having a firm grasp on them. – Kuba hasn't forgotten Monica Apr 01 '14 at 17:49
  • 1
    "I don't know, I just click on Build button in QT creator" You should stop *right here* and look at what happens when you do in fact click that button. [Get a rubber duck](http://en.wikipedia.org/wiki/Rubber_duck_debugging). Explain to the duck what processes run, and in what order, and in what working directories, when you do so. Don't come back until you have that understanding. Otherwise you'll be running in circles until the world ends. If you wish to be *told* what runs and how, you should ask another question. – Kuba hasn't forgotten Monica Apr 01 '14 at 17:52
  • @KubaOber Thanks, I think you are right... I must read some tutorials to get understanding what is really happens when I build Qt program. – Boris Mitioglov Apr 01 '14 at 17:57

0 Answers0