Reputation: 11
Hey I've got a really simple qt program that doesn't seem to compile. The error I get is "symbol(s) not found for architecture x86_64" and "linker command failed with exit code 1(use -v to see invocation)". PS: i use a mac os X version 10.9.2. I tried making the destructor virtual and putting the class in a separate header file. Neither worked.
Error:
Undefined symbols for architecture x86_64:
"vtable for QQ", referenced from:
QQ::QQ(QWidget*) in main.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Test.app/Contents/MacOS/Test] Error 1
14:42:46: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project Test (kit: Desktop Qt 5.2.1 clang 64bit)
When executing step 'Make'
Here is my code:
#include "qmainwindow.h"
#include <QApplication>
#include <QPushButton>
#include <QObject>
#include <iostream>
#include <QTextEdit>
#include <QVBoxLayout>
using namespace std;
class QQ: public QWidget{
Q_OBJECT
public:
explicit QQ(QWidget* parent = 0) { };
virtual ~QQ() { };
void print(){cout << value;};
public slots:
void changev(int n){value = 135;};
private:
int value;
};
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QMainWindow mw;
QQ* a = new QQ(&mw);
//QPushButton* qp = new QPushButton("here");
//QObject::connect(qp, SIGNAL(clicked()), a, SLOT(changev(9)));
return app.exec();
}
Upvotes: 1
Views: 4019
Reputation: 24916
I had the same thing happen to me. My application compiled perfectly fine, but then stopped compiling and showed these same 2 errors. I tried Build > Build All, Build > qmake, Build > Clean All, and Build > Run, but nothing worked. I deleted the .user file in the project (with QtCreator shut down) and ran qmake followed by run again, and that still didn't help. Somehow, the project got corrupt.
Luckily, I had a backup from the previous day. So, I copied over the backup, added in the new changes from the other corrupt project, recompiled, and voila -- it worked!
Upvotes: -1
Reputation: 205
Your problem seems to stem from the Q_OBJECT
declaration. On my machine, simply moving the QQ
class to a separate header file did the trick. Remember to make clean
and run qmake -project
and qmake
again after moving the class to a header file.
Refer to the following question for more details: Q_OBJECT throwing 'undefined reference to vtable' error
Upvotes: 2