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
c++ linux qt class can
|
show 1 more comment
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
c++ linux qt class can
"undefined reference to <foo>" usually means you forgot to link the library or object file implementingfoo
(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 linestatic QCanBus *instance();
not definingQCanBus::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
|
show 1 more comment
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
c++ linux qt class can
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
c++ linux qt class can
asked Nov 7 at 18:28
viduwoy
107
107
"undefined reference to <foo>" usually means you forgot to link the library or object file implementingfoo
(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 linestatic QCanBus *instance();
not definingQCanBus::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
|
show 1 more comment
"undefined reference to <foo>" usually means you forgot to link the library or object file implementingfoo
(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 linestatic QCanBus *instance();
not definingQCanBus::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
|
show 1 more comment
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
"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 definingQCanBus::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