undefined reference to `vtable for shutdown'
-
@J-Hilk , unfortunately not, the build process is entirely using cmake. I've just renamed the build folder and then started off the build again with a new build folder, all the object files were in subfolders of the build folder.
@SPlatten said in undefined reference to `vtable for shutdown':
@J-Hilk , unfortunately not, the build process is entirely using cmake.
qmake or cmake make no difference here, build directory is what you're looking for
-
@SPlatten said in undefined reference to `vtable for shutdown':
@J-Hilk , unfortunately not, the build process is entirely using cmake.
qmake or cmake make no difference here, build directory is what you're looking for
-
@SPlatten ok, one point less to check, very unusual
ok, try adding
virtual
to your destructor declaration.did you post the whole class?
are there any other functions, virtual or not, in there? -
@SPlatten ok, one point less to check, very unusual
ok, try adding
virtual
to your destructor declaration.did you post the whole class?
are there any other functions, virtual or not, in there? -
@J-Hilk . that was the entire class, I've added virtual to the destructor prototype, rebuilding now.
@SPlatten did you make changes in your CMakeLists.txt ?
I assume you have
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set (CMAKE_INCLUDE_CURRENT_DIR ON)in it ?
and
set(PROJECT_SOURCES ....)contains your new class ?
as well as
qt5_wrap_cppqt4_wrap_cpp() (I think that was needed for older version ?) -
@SPlatten did you make changes in your CMakeLists.txt ?
I assume you have
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set (CMAKE_INCLUDE_CURRENT_DIR ON)in it ?
and
set(PROJECT_SOURCES ....)contains your new class ?
as well as
qt5_wrap_cppqt4_wrap_cpp() (I think that was needed for older version ?)@J-Hilk , I've added the set calls from your post to the make file, the qt4 bits that I did have:
find_package(Qt4 REQUIRED) include(${QT_USE_FILE}) foreach(loop_var ${QT_LIBRARIES}) string(REPLACE lib64 lib32 loop_var ${loop_var}) set(QT_LIBRARIES_32 ${QT_LIBRARIES_32} ${loop_var}) endforeach(loop_var) qt4_wrap_ui(UI_HEADERS ${FORMS}) qt4_wrap_cpp(MOC_SRCS ${HEADERS})
-
@SPlatten did you make changes in your CMakeLists.txt ?
I assume you have
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set (CMAKE_INCLUDE_CURRENT_DIR ON)in it ?
and
set(PROJECT_SOURCES ....)contains your new class ?
as well as
qt5_wrap_cppqt4_wrap_cpp() (I think that was needed for older version ?) -
@SPlatten Well,
I'm sorry to say it, but I'm out of ideas. My experience with cmake is very limited and does not reach further :(
-
@SPlatten in your source dir where cmake file is located do the following:
mkdir build
cd build
cmake .. -Dyour settings
make -j4Try to build your code in the build folder all the time. In case you have your vtable issues, simply rm -rf * to delete everything in build dir and redo cmake. Do this only in build dir. Be very careful with rm -rf *. You have to have svn or git for your sources.
-
@SPlatten in your source dir where cmake file is located do the following:
mkdir build
cd build
cmake .. -Dyour settings
make -j4Try to build your code in the build folder all the time. In case you have your vtable issues, simply rm -rf * to delete everything in build dir and redo cmake. Do this only in build dir. Be very careful with rm -rf *. You have to have svn or git for your sources.
-
@JoeCFD , thank you, will give this a go now, I've been doing the following:
Delete build folder
Create build folder
From build folder cmake ${myvariable}
From build folder makeI will try using -j4 on the make.
@SPlatten
Wellmake -j4
isn't going to fix anything :)Your code looks right to me (especially the
Q_OBJECT
, whose absence/change can often cause this). Given that you say you have cleaned everything out and rebuilt I am not sure what is wrong (unless there is some artefact left around somewhere it is still seeing).From the linker messages
undefined reference to vtable for 'shutdown'
I am unsure whether it is talking about yourclass shutdown : public QMainWindow {
or the Qt-Designer-generatednamespace Ui { class shutdown; }
(Ui::shutdown
). You might just check what is in the generatedui_shutdown.h
file to see if it looks good.... (and if that has not been being regenerated, delete it or update the.ui
file to make it regenerate, just in case). -
@SPlatten in your source dir where cmake file is located do the following:
mkdir build
cd build
cmake .. -Dyour settings
make -j4Try to build your code in the build folder all the time. In case you have your vtable issues, simply rm -rf * to delete everything in build dir and redo cmake. Do this only in build dir. Be very careful with rm -rf *. You have to have svn or git for your sources.
-
@SPlatten
Wellmake -j4
isn't going to fix anything :)Your code looks right to me (especially the
Q_OBJECT
, whose absence/change can often cause this). Given that you say you have cleaned everything out and rebuilt I am not sure what is wrong (unless there is some artefact left around somewhere it is still seeing).From the linker messages
undefined reference to vtable for 'shutdown'
I am unsure whether it is talking about yourclass shutdown : public QMainWindow {
or the Qt-Designer-generatednamespace Ui { class shutdown; }
(Ui::shutdown
). You might just check what is in the generatedui_shutdown.h
file to see if it looks good.... (and if that has not been being regenerated, delete it or update the.ui
file to make it regenerate, just in case).@JonB , thank you, here is ui_shutdown.h:
#ifndef UI_SHUTDOWN_H #define UI_SHUTDOWN_H #include <QtCore/QVariant> #include <QtGui/QAction> #include <QtGui/QApplication> #include <QtGui/QButtonGroup> #include <QtGui/QHeaderView> #inlcude <QtGui/QLabel> #include <QtGui/QMainWindow> #include <QtGui/QWidget> QT_BEGIN_NAMESPACE class Ui_shutdown { public: QWidget *centralWidget; QLabel *plblText; void setupUi(QMainWindow *shutdown) { if ( shutdown->objectName().isEmpty()) shutdown->setObjectName(QString::fromUtf8("shutdown")); shutdown->resize(171, 73); shutdown->setStyleSheet(QString::fromUtf8("background-color: #0790ff;\n" "color:#ffffff;\n" "")); centralWidget = new QWidget(shutdown); centralWidget->setObjectName(QString::fromUtf8("centralWidget")); plblText = new QLabel(centralWidget); plblText->setObjectName(QString::fromUtf8("plblText")); plblText->setGeometry(QRect(0, 0, 171, 71)); plblText->setStyleSheet(QString::fromUtf8("vertical-align:middle;\n" "text-align: center;\n" "font-weight: bold;\n" "")); plblText->setAlignment(Qt::AlignCenter); shutdown->setCentralWidget(centralWidget); retranslateUi(shutdown); QMetaObject::connectSlotsByName(shutdown); } // setupUi void retranslateUi(QMainWindow *shutdown) { shutdown->setWindowTitle(QString()); plblText->setText(QApplication::translate("shutdown", "Shutting down...", 0, QApplication::UnicodeUTF8)); } // retranslateUi }; namespace Ui { class shutdown: public Ui_shutdown {}; } // namespace Ui QT_END_NAMESPACE #endif // UI_SHUTDOWN_H
-
I am working on a project using Qt 4.8.4, the revision of Qt is something I have no control over. I have added a class one of the libraries which are built with cmake, here is the prototype:
shutdown.h:
#ifndef SHUTDOWN_H #define SHUTDOWN_H #include <QApplication> #include <QDesktopWidget> #include <QMainWindow> namespace Ui { class shutdown; } class shutdown : public QMainWindow { Q_OBJECT public: explicit shutdown(const char* cpszText, QWidget* pParent = 0); ~shutdown(); private: Ui::shutdown* ui; }; #endif // SHUTDOWN_H
#include "shutdown.h" #include "ui_shutdown.h" shutdown::shutdown(const char* cpszText, QWidget* pParent) : QMainWindow(pParent), ui(new Ui::shutdown) { ui->setupUi(this); if ( cpszText ) { ui->plblText->setText(cpszText); } } shutdown::~shutdown() { delete ui; }
I've checked CMakeLists.txt which includes the CC file, however when build completes I get:
../../(shutdown.cc.o): In function `shutdown::shutdown(char const*, QWidget*)': shutdown.cc: (.text+0x3a): undefined reference to `vtable for shutdown' shutdown.cc: (.text+0x41): undefined reference to `vtable for shutdown' ../../(shutdown.cc.o): In function `shutdown::~shutdown()': shutdown.cc: (.text+0x4cd): undefined reference to `vtable for shutdown' shutdown.cc: (.text+0x4d4): undefined reference to `vtable for shutdown' collect2: ld returned 1 exit status make[2]: *** [file name] Error 1 make[2] Leaving directory 'location' make[1] ** [filename.dir/all] Error 2 make[1] Leaving directory 'location' make: *** [all] Error 2
@SPlatten said in undefined reference to `vtable for shutdown':
../../(shutdown.cc.o): In function `shutdown::shutdown(char const*, QWidget*)':
Note that this
.o
file is being found in../..
from where you are/the compiler is being run. Is that indeed correct for you, and where you have deleting files from? Do you by any chance have any othershutdown.cc.o
file lying around anywhere from, say, the whole of../..
downward?I have no experience of " I have added a class one of the libraries which are built with cmake". But when you do a complete rebuild I am expecting you to see among the commands:
- A
uic
run on onshutdown.ui
, producingui_shutdown.h
. - A
cc
(or whatever) compilation run onshutdown.cc
, producingshutdown.o
. - A
cc
onmoc_shotdown.cc
, or similar, producing <can't recall>. - Some kind of
ld
(or maybecc
) doing the linking. It will involveshutdown.cc.o
, I can't remember how moc works, whether there is amoc_shutdown.cc.o
or just themoc_shutdown.h
or whatever source file.
This is not for you to paste the whole output here, it's for you to look at just to verify. It ought be correct anyway.
- A
-
@SPlatten ~shutdown() has to be virtual. It is better to start with upper case in your class name(Shutdown). Normally function starts with lower case.
also make sure shutdown.cpp is added to cmake fileexplicit shutdown(const char* cpszText, QWidget* pParent = 0); virtual ~shutdown();
-
@SPlatten ~shutdown() has to be virtual. It is better to start with upper case in your class name(Shutdown). Normally function starts with lower case.
also make sure shutdown.cpp is added to cmake fileexplicit shutdown(const char* cpszText, QWidget* pParent = 0); virtual ~shutdown();
@SPlatten said in undefined reference to `vtable for shutdown':
@J-Hilk . that was the entire class, I've added virtual to the destructor prototype, rebuilding now.
@SPlatten
Let's be clear: you are now compiling withpublic: explicit shutdown(const char* cpszText, QWidget* pParent = 0); virtual ~shutdown();
right?
-
@SPlatten said in undefined reference to `vtable for shutdown':
@J-Hilk . that was the entire class, I've added virtual to the destructor prototype, rebuilding now.
@SPlatten
Let's be clear: you are now compiling withpublic: explicit shutdown(const char* cpszText, QWidget* pParent = 0); virtual ~shutdown();
right?
-
@SPlatten said in undefined reference to `vtable for shutdown':
../../(shutdown.cc.o): In function `shutdown::shutdown(char const*, QWidget*)':
Note that this
.o
file is being found in../..
from where you are/the compiler is being run. Is that indeed correct for you, and where you have deleting files from? Do you by any chance have any othershutdown.cc.o
file lying around anywhere from, say, the whole of../..
downward?I have no experience of " I have added a class one of the libraries which are built with cmake". But when you do a complete rebuild I am expecting you to see among the commands:
- A
uic
run on onshutdown.ui
, producingui_shutdown.h
. - A
cc
(or whatever) compilation run onshutdown.cc
, producingshutdown.o
. - A
cc
onmoc_shotdown.cc
, or similar, producing <can't recall>. - Some kind of
ld
(or maybecc
) doing the linking. It will involveshutdown.cc.o
, I can't remember how moc works, whether there is amoc_shutdown.cc.o
or just themoc_shutdown.h
or whatever source file.
This is not for you to paste the whole output here, it's for you to look at just to verify. It ought be correct anyway.
- A