Qt creator Undefined reference to “class::function” in linux











up vote
0
down vote

favorite












This question is similar to one that has been asked before, but I am having an issue with Qt recognizing my class and functions despite them being defined. I am doing this in linux where the Qt version is only 5.5 while the windows version is at 5.11. When running the same program in windows, I get no errors.



I am getting "undefined reference to QCanBus::instance()" errors



This is happening for every QCanBus function. In my code snippet from connectdialogue.cpp, only the first occurrence is featured and can be found at the second to last code line and gives the errors:



"undefined reference to QCanBus::instance()"



"undefined reference to QCanBus::plugins()"



These errors are given despite being defined in the qcanbus.h headder file.



I have tried adding the lines static QCanBus *instance() or alternatively QCanBus *instance() under the #include lines in my connectdialogue.cpp, but I am then presented with the warning:
"QCanBus::instance() is defined, but unused" when it is clearly used on the second to last line of the featured code snippet.



How do I fix these errors?



connectdialogue.cpp



 #include "connectdialog.h"
#include "ui_connectdialog.h"

#include "qcanbus.h"

ConnectDialog::ConnectDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::ConnectDialog)
{
m_ui->setupUi(this);

m_ui->errorFilterEdit->setValidator(new QIntValidator(0, 0x1FFFFFFFU, this));

m_ui->loopbackBox->addItem(tr("unspecified"), QVariant());
m_ui->loopbackBox->addItem(tr("false"), QVariant(false));
m_ui->loopbackBox->addItem(tr("true"), QVariant(true));

m_ui->receiveOwnBox->addItem(tr("unspecified"), QVariant());
m_ui->receiveOwnBox->addItem(tr("false"), QVariant(false));
m_ui->receiveOwnBox->addItem(tr("true"), QVariant(true));

m_ui->canFdBox->addItem(tr("false"), QVariant(false));
m_ui->canFdBox->addItem(tr("true"), QVariant(true));

m_ui->dataBitrateBox->setFlexibleDateRateEnabled(true);

connect(m_ui->okButton, &QPushButton::clicked, this, &ConnectDialog::ok);
connect(m_ui->cancelButton, &QPushButton::clicked, this, &ConnectDialog::cancel);
connect(m_ui->useConfigurationBox, &QCheckBox::clicked,
m_ui->configurationBox, &QGroupBox::setEnabled);
connect(m_ui->backendListBox, &QComboBox::currentTextChanged,
this, &ConnectDialog::backendChanged);
connect(m_ui->interfaceListBox, &QComboBox::currentTextChanged,
this, &ConnectDialog::interfaceChanged);
m_ui->rawFilterEdit->hide();
m_ui->rawFilterLabel->hide();

m_ui->backendListBox->addItems(QCanBus::instance()->plugins());

updateSettings();
}


qcanbus.h



#ifndef QCANBUS_H
#define QCANBUS_H

#include <QtCore/qobject.h>
#include "qserialbusglobal.h"
#include "qcanbusdevice.h"
#include "qcanbusdeviceinfo.h"

QT_BEGIN_NAMESPACE

class Q_SERIALBUS_EXPORT QCanBus : public QObject
{
Q_OBJECT

public:
static QCanBus *instance();
QStringList plugins() const;

QList<QCanBusDeviceInfo> availableDevices(const QString &plugin, QString *errorMessage = nullptr) const;

QCanBusDevice *createDevice(const QString &plugin,
const QString &interfaceName,
QString *errorMessage = nullptr) const;

private:
QCanBus(QObject *parent = nullptr);

Q_DISABLE_COPY(QCanBus)
};

QT_END_NAMESPACE

#endif // QSERIALBUS_H









share|improve this question






















  • "undefined reference to <foo>" usually means you forgot to link the library or object file implementing foo (or linked them in the wrong order).
    – Jesper Juhl
    Nov 7 at 18:36










  • There are no definitions of those in your header.
    – molbdnilo
    Nov 7 at 18:39










  • @molbdnilo where/how would I need to define it? Is the line static QCanBus *instance(); not defining QCanBus::instance()?
    – viduwoy
    Nov 7 at 18:48










  • @JesperJuhl that is entirely possible since I am importing missing files in linux from windows. How could I go about finding the missing library or object file? I already have all the dependent #include files.
    – viduwoy
    Nov 7 at 18:50












  • @viduwoy you could look through the source to find whatever defines the symbol, then look through your build system files to see what that source gets build into. You could just objdump all your object/library files and grep for the symbol in question. You could read documentation to see if it tells you what to link against. There are many ways to find out.
    – Jesper Juhl
    Nov 7 at 18:54















up vote
0
down vote

favorite












This question is similar to one that has been asked before, but I am having an issue with Qt recognizing my class and functions despite them being defined. I am doing this in linux where the Qt version is only 5.5 while the windows version is at 5.11. When running the same program in windows, I get no errors.



I am getting "undefined reference to QCanBus::instance()" errors



This is happening for every QCanBus function. In my code snippet from connectdialogue.cpp, only the first occurrence is featured and can be found at the second to last code line and gives the errors:



"undefined reference to QCanBus::instance()"



"undefined reference to QCanBus::plugins()"



These errors are given despite being defined in the qcanbus.h headder file.



I have tried adding the lines static QCanBus *instance() or alternatively QCanBus *instance() under the #include lines in my connectdialogue.cpp, but I am then presented with the warning:
"QCanBus::instance() is defined, but unused" when it is clearly used on the second to last line of the featured code snippet.



How do I fix these errors?



connectdialogue.cpp



 #include "connectdialog.h"
#include "ui_connectdialog.h"

#include "qcanbus.h"

ConnectDialog::ConnectDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::ConnectDialog)
{
m_ui->setupUi(this);

m_ui->errorFilterEdit->setValidator(new QIntValidator(0, 0x1FFFFFFFU, this));

m_ui->loopbackBox->addItem(tr("unspecified"), QVariant());
m_ui->loopbackBox->addItem(tr("false"), QVariant(false));
m_ui->loopbackBox->addItem(tr("true"), QVariant(true));

m_ui->receiveOwnBox->addItem(tr("unspecified"), QVariant());
m_ui->receiveOwnBox->addItem(tr("false"), QVariant(false));
m_ui->receiveOwnBox->addItem(tr("true"), QVariant(true));

m_ui->canFdBox->addItem(tr("false"), QVariant(false));
m_ui->canFdBox->addItem(tr("true"), QVariant(true));

m_ui->dataBitrateBox->setFlexibleDateRateEnabled(true);

connect(m_ui->okButton, &QPushButton::clicked, this, &ConnectDialog::ok);
connect(m_ui->cancelButton, &QPushButton::clicked, this, &ConnectDialog::cancel);
connect(m_ui->useConfigurationBox, &QCheckBox::clicked,
m_ui->configurationBox, &QGroupBox::setEnabled);
connect(m_ui->backendListBox, &QComboBox::currentTextChanged,
this, &ConnectDialog::backendChanged);
connect(m_ui->interfaceListBox, &QComboBox::currentTextChanged,
this, &ConnectDialog::interfaceChanged);
m_ui->rawFilterEdit->hide();
m_ui->rawFilterLabel->hide();

m_ui->backendListBox->addItems(QCanBus::instance()->plugins());

updateSettings();
}


qcanbus.h



#ifndef QCANBUS_H
#define QCANBUS_H

#include <QtCore/qobject.h>
#include "qserialbusglobal.h"
#include "qcanbusdevice.h"
#include "qcanbusdeviceinfo.h"

QT_BEGIN_NAMESPACE

class Q_SERIALBUS_EXPORT QCanBus : public QObject
{
Q_OBJECT

public:
static QCanBus *instance();
QStringList plugins() const;

QList<QCanBusDeviceInfo> availableDevices(const QString &plugin, QString *errorMessage = nullptr) const;

QCanBusDevice *createDevice(const QString &plugin,
const QString &interfaceName,
QString *errorMessage = nullptr) const;

private:
QCanBus(QObject *parent = nullptr);

Q_DISABLE_COPY(QCanBus)
};

QT_END_NAMESPACE

#endif // QSERIALBUS_H









share|improve this question






















  • "undefined reference to <foo>" usually means you forgot to link the library or object file implementing foo (or linked them in the wrong order).
    – Jesper Juhl
    Nov 7 at 18:36










  • There are no definitions of those in your header.
    – molbdnilo
    Nov 7 at 18:39










  • @molbdnilo where/how would I need to define it? Is the line static QCanBus *instance(); not defining QCanBus::instance()?
    – viduwoy
    Nov 7 at 18:48










  • @JesperJuhl that is entirely possible since I am importing missing files in linux from windows. How could I go about finding the missing library or object file? I already have all the dependent #include files.
    – viduwoy
    Nov 7 at 18:50












  • @viduwoy you could look through the source to find whatever defines the symbol, then look through your build system files to see what that source gets build into. You could just objdump all your object/library files and grep for the symbol in question. You could read documentation to see if it tells you what to link against. There are many ways to find out.
    – Jesper Juhl
    Nov 7 at 18:54













up vote
0
down vote

favorite









up vote
0
down vote

favorite











This question is similar to one that has been asked before, but I am having an issue with Qt recognizing my class and functions despite them being defined. I am doing this in linux where the Qt version is only 5.5 while the windows version is at 5.11. When running the same program in windows, I get no errors.



I am getting "undefined reference to QCanBus::instance()" errors



This is happening for every QCanBus function. In my code snippet from connectdialogue.cpp, only the first occurrence is featured and can be found at the second to last code line and gives the errors:



"undefined reference to QCanBus::instance()"



"undefined reference to QCanBus::plugins()"



These errors are given despite being defined in the qcanbus.h headder file.



I have tried adding the lines static QCanBus *instance() or alternatively QCanBus *instance() under the #include lines in my connectdialogue.cpp, but I am then presented with the warning:
"QCanBus::instance() is defined, but unused" when it is clearly used on the second to last line of the featured code snippet.



How do I fix these errors?



connectdialogue.cpp



 #include "connectdialog.h"
#include "ui_connectdialog.h"

#include "qcanbus.h"

ConnectDialog::ConnectDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::ConnectDialog)
{
m_ui->setupUi(this);

m_ui->errorFilterEdit->setValidator(new QIntValidator(0, 0x1FFFFFFFU, this));

m_ui->loopbackBox->addItem(tr("unspecified"), QVariant());
m_ui->loopbackBox->addItem(tr("false"), QVariant(false));
m_ui->loopbackBox->addItem(tr("true"), QVariant(true));

m_ui->receiveOwnBox->addItem(tr("unspecified"), QVariant());
m_ui->receiveOwnBox->addItem(tr("false"), QVariant(false));
m_ui->receiveOwnBox->addItem(tr("true"), QVariant(true));

m_ui->canFdBox->addItem(tr("false"), QVariant(false));
m_ui->canFdBox->addItem(tr("true"), QVariant(true));

m_ui->dataBitrateBox->setFlexibleDateRateEnabled(true);

connect(m_ui->okButton, &QPushButton::clicked, this, &ConnectDialog::ok);
connect(m_ui->cancelButton, &QPushButton::clicked, this, &ConnectDialog::cancel);
connect(m_ui->useConfigurationBox, &QCheckBox::clicked,
m_ui->configurationBox, &QGroupBox::setEnabled);
connect(m_ui->backendListBox, &QComboBox::currentTextChanged,
this, &ConnectDialog::backendChanged);
connect(m_ui->interfaceListBox, &QComboBox::currentTextChanged,
this, &ConnectDialog::interfaceChanged);
m_ui->rawFilterEdit->hide();
m_ui->rawFilterLabel->hide();

m_ui->backendListBox->addItems(QCanBus::instance()->plugins());

updateSettings();
}


qcanbus.h



#ifndef QCANBUS_H
#define QCANBUS_H

#include <QtCore/qobject.h>
#include "qserialbusglobal.h"
#include "qcanbusdevice.h"
#include "qcanbusdeviceinfo.h"

QT_BEGIN_NAMESPACE

class Q_SERIALBUS_EXPORT QCanBus : public QObject
{
Q_OBJECT

public:
static QCanBus *instance();
QStringList plugins() const;

QList<QCanBusDeviceInfo> availableDevices(const QString &plugin, QString *errorMessage = nullptr) const;

QCanBusDevice *createDevice(const QString &plugin,
const QString &interfaceName,
QString *errorMessage = nullptr) const;

private:
QCanBus(QObject *parent = nullptr);

Q_DISABLE_COPY(QCanBus)
};

QT_END_NAMESPACE

#endif // QSERIALBUS_H









share|improve this question













This question is similar to one that has been asked before, but I am having an issue with Qt recognizing my class and functions despite them being defined. I am doing this in linux where the Qt version is only 5.5 while the windows version is at 5.11. When running the same program in windows, I get no errors.



I am getting "undefined reference to QCanBus::instance()" errors



This is happening for every QCanBus function. In my code snippet from connectdialogue.cpp, only the first occurrence is featured and can be found at the second to last code line and gives the errors:



"undefined reference to QCanBus::instance()"



"undefined reference to QCanBus::plugins()"



These errors are given despite being defined in the qcanbus.h headder file.



I have tried adding the lines static QCanBus *instance() or alternatively QCanBus *instance() under the #include lines in my connectdialogue.cpp, but I am then presented with the warning:
"QCanBus::instance() is defined, but unused" when it is clearly used on the second to last line of the featured code snippet.



How do I fix these errors?



connectdialogue.cpp



 #include "connectdialog.h"
#include "ui_connectdialog.h"

#include "qcanbus.h"

ConnectDialog::ConnectDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::ConnectDialog)
{
m_ui->setupUi(this);

m_ui->errorFilterEdit->setValidator(new QIntValidator(0, 0x1FFFFFFFU, this));

m_ui->loopbackBox->addItem(tr("unspecified"), QVariant());
m_ui->loopbackBox->addItem(tr("false"), QVariant(false));
m_ui->loopbackBox->addItem(tr("true"), QVariant(true));

m_ui->receiveOwnBox->addItem(tr("unspecified"), QVariant());
m_ui->receiveOwnBox->addItem(tr("false"), QVariant(false));
m_ui->receiveOwnBox->addItem(tr("true"), QVariant(true));

m_ui->canFdBox->addItem(tr("false"), QVariant(false));
m_ui->canFdBox->addItem(tr("true"), QVariant(true));

m_ui->dataBitrateBox->setFlexibleDateRateEnabled(true);

connect(m_ui->okButton, &QPushButton::clicked, this, &ConnectDialog::ok);
connect(m_ui->cancelButton, &QPushButton::clicked, this, &ConnectDialog::cancel);
connect(m_ui->useConfigurationBox, &QCheckBox::clicked,
m_ui->configurationBox, &QGroupBox::setEnabled);
connect(m_ui->backendListBox, &QComboBox::currentTextChanged,
this, &ConnectDialog::backendChanged);
connect(m_ui->interfaceListBox, &QComboBox::currentTextChanged,
this, &ConnectDialog::interfaceChanged);
m_ui->rawFilterEdit->hide();
m_ui->rawFilterLabel->hide();

m_ui->backendListBox->addItems(QCanBus::instance()->plugins());

updateSettings();
}


qcanbus.h



#ifndef QCANBUS_H
#define QCANBUS_H

#include <QtCore/qobject.h>
#include "qserialbusglobal.h"
#include "qcanbusdevice.h"
#include "qcanbusdeviceinfo.h"

QT_BEGIN_NAMESPACE

class Q_SERIALBUS_EXPORT QCanBus : public QObject
{
Q_OBJECT

public:
static QCanBus *instance();
QStringList plugins() const;

QList<QCanBusDeviceInfo> availableDevices(const QString &plugin, QString *errorMessage = nullptr) const;

QCanBusDevice *createDevice(const QString &plugin,
const QString &interfaceName,
QString *errorMessage = nullptr) const;

private:
QCanBus(QObject *parent = nullptr);

Q_DISABLE_COPY(QCanBus)
};

QT_END_NAMESPACE

#endif // QSERIALBUS_H






c++ linux qt class can






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 7 at 18:28









viduwoy

107




107












  • "undefined reference to <foo>" usually means you forgot to link the library or object file implementing foo (or linked them in the wrong order).
    – Jesper Juhl
    Nov 7 at 18:36










  • There are no definitions of those in your header.
    – molbdnilo
    Nov 7 at 18:39










  • @molbdnilo where/how would I need to define it? Is the line static QCanBus *instance(); not defining QCanBus::instance()?
    – viduwoy
    Nov 7 at 18:48










  • @JesperJuhl that is entirely possible since I am importing missing files in linux from windows. How could I go about finding the missing library or object file? I already have all the dependent #include files.
    – viduwoy
    Nov 7 at 18:50












  • @viduwoy you could look through the source to find whatever defines the symbol, then look through your build system files to see what that source gets build into. You could just objdump all your object/library files and grep for the symbol in question. You could read documentation to see if it tells you what to link against. There are many ways to find out.
    – Jesper Juhl
    Nov 7 at 18:54


















  • "undefined reference to <foo>" usually means you forgot to link the library or object file implementing foo (or linked them in the wrong order).
    – Jesper Juhl
    Nov 7 at 18:36










  • There are no definitions of those in your header.
    – molbdnilo
    Nov 7 at 18:39










  • @molbdnilo where/how would I need to define it? Is the line static QCanBus *instance(); not defining QCanBus::instance()?
    – viduwoy
    Nov 7 at 18:48










  • @JesperJuhl that is entirely possible since I am importing missing files in linux from windows. How could I go about finding the missing library or object file? I already have all the dependent #include files.
    – viduwoy
    Nov 7 at 18:50












  • @viduwoy you could look through the source to find whatever defines the symbol, then look through your build system files to see what that source gets build into. You could just objdump all your object/library files and grep for the symbol in question. You could read documentation to see if it tells you what to link against. There are many ways to find out.
    – Jesper Juhl
    Nov 7 at 18:54
















"undefined reference to <foo>" usually means you forgot to link the library or object file implementing foo (or linked them in the wrong order).
– Jesper Juhl
Nov 7 at 18:36




"undefined reference to <foo>" usually means you forgot to link the library or object file implementing foo (or linked them in the wrong order).
– Jesper Juhl
Nov 7 at 18:36












There are no definitions of those in your header.
– molbdnilo
Nov 7 at 18:39




There are no definitions of those in your header.
– molbdnilo
Nov 7 at 18:39












@molbdnilo where/how would I need to define it? Is the line static QCanBus *instance(); not defining QCanBus::instance()?
– viduwoy
Nov 7 at 18:48




@molbdnilo where/how would I need to define it? Is the line static QCanBus *instance(); not defining QCanBus::instance()?
– viduwoy
Nov 7 at 18:48












@JesperJuhl that is entirely possible since I am importing missing files in linux from windows. How could I go about finding the missing library or object file? I already have all the dependent #include files.
– viduwoy
Nov 7 at 18:50






@JesperJuhl that is entirely possible since I am importing missing files in linux from windows. How could I go about finding the missing library or object file? I already have all the dependent #include files.
– viduwoy
Nov 7 at 18:50














@viduwoy you could look through the source to find whatever defines the symbol, then look through your build system files to see what that source gets build into. You could just objdump all your object/library files and grep for the symbol in question. You could read documentation to see if it tells you what to link against. There are many ways to find out.
– Jesper Juhl
Nov 7 at 18:54




@viduwoy you could look through the source to find whatever defines the symbol, then look through your build system files to see what that source gets build into. You could just objdump all your object/library files and grep for the symbol in question. You could read documentation to see if it tells you what to link against. There are many ways to find out.
– Jesper Juhl
Nov 7 at 18:54

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195603%2fqt-creator-undefined-reference-to-classfunction-in-linux%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195603%2fqt-creator-undefined-reference-to-classfunction-in-linux%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()