Qt - Unresolved externals, again, again

Getting unresolved externals for a basic example of opengl i found online?

Code and include file descriptions attached...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "stdafx.h"
#include <QtGui/QApplication>
#include <QGLWidget>
#include <QMouseEvent>
#include <QColorDialog>

class Tetrahedron : public QGLWidget
{
Q_OBJECT
public:
	Tetrahedron(QWidget *parent = 0);
protected:
	void initializeGL();
	void resizeGL(int width, int height);
	void paintGL();
private:
	void draw();
	GLfloat rotationX;
	GLfloat rotationY;
	GLfloat rotationZ;
	QColor faceColors[4];
	QPoint lastPos;
};

Tetrahedron::Tetrahedron(QWidget *parent)
: QGLWidget(parent)
{
	setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer));
	rotationX = -21.0;
	rotationY = -57.0;
	rotationZ = 0.0;
	faceColors[0] = Qt::red;
	faceColors[1] = Qt::green;
	faceColors[2] = Qt::blue;
	faceColors[3] = Qt::yellow;
}

void Tetrahedron::initializeGL()

{
	qglClearColor(Qt::black);
	glShadeModel(GL_FLAT);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
}

void Tetrahedron::resizeGL(int width, int height)
{
	glViewport(0, 0, width, height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	GLfloat x = GLfloat(width) / height;
	glFrustum(-x, +x, -1.0, +1.0, 4.0, 15.0);
	glMatrixMode(GL_MODELVIEW);
}

void Tetrahedron::paintGL()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	draw();
}

void Tetrahedron::draw()
{
	static const GLfloat P1[3] = { 0.0, -1.0, +2.0 };
	static const GLfloat P2[3] = { +1.73205081, -1.0, -1.0 };
	static const GLfloat P3[3] = { -1.73205081, -1.0, -1.0 };
	static const GLfloat P4[3] = { 0.0, +2.0, 0.0 };
	static const GLfloat * const coords[4][3] = {
		{ P1, P2, P3 }, { P1, P3, P4 }, { P1, P4, P2 }, { P2, P4, P3 }
	};
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef(0.0, 0.0, -10.0);
	glRotatef(rotationX, 1.0, 0.0, 0.0);
	glRotatef(rotationY, 0.0, 1.0, 0.0);
	glRotatef(rotationZ, 0.0, 0.0, 1.0);
	for (int i = 0; i < 4; ++i) {
		glLoadName(i);
		glBegin(GL_TRIANGLES);
		qglColor(faceColors[i]);
		for (int j = 0; j < 3; ++j) {
			glVertex3f(coords[i][j][0], coords[i][j][1],
			coords[i][j][2]);
		}
		glEnd();
	}
}

int main(int argc, char *argv[])
{
	QApplication app(argc, argv);
	Tetrahedron tetrahedron;
	tetrahedron.setWindowTitle(QObject::tr("Tetrahedron"));
	tetrahedron.resize(300, 300);
	tetrahedron.show();
	return app.exec();
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# ----------------------------------------------------
# This file is generated by the Qt Visual Studio Add-in.
# ------------------------------------------------------

TEMPLATE = app
TARGET = anothertryqt
DESTDIR = ../Win32/Debug
QT += core gui opengl
CONFIG += debug console
DEFINES += QT_LARGEFILE_SUPPORT QT_DLL QT_OPENGL_LIB
INCLUDEPATH += . \
    ./GeneratedFiles/Debug
LIBS += -lopengl32 \
    -lglu32
PRECOMPILED_HEADER = StdAfx.h
DEPENDPATH += .
MOC_DIR += ./GeneratedFiles/debug
OBJECTS_DIR += debug
UI_DIR += ./GeneratedFiles
RCC_DIR += ./GeneratedFiles
include(anothertryqt.pri)


1
2
3
4
5
6
7
Error	1	error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall Tetrahedron::metaObject(void)const " (?metaObject@Tetrahedron@@UBEPBUQMetaObject@@XZ)	main.obj	anothertryqt

Error	2	error LNK2001: unresolved external symbol "public: virtual void * __thiscall Tetrahedron::qt_metacast(char const *)" (?qt_metacast@Tetrahedron@@UAEPAXPBD@Z)	main.obj	anothertryqt

Error	3	error LNK2001: unresolved external symbol "public: virtual int __thiscall Tetrahedron::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Tetrahedron@@UAEHW4Call@QMetaObject@@HPAPAX@Z)	main.obj	anothertryqt

Error	4	fatal error LNK1120: 3 unresolved externals	C:\Users\Beakie\Documents\Visual Studio 2008\Projects\anothertryqt\Win32\Debug\anothertryqt.exe	anothertryqt
I'm not familiar with Qt, but....


"unresolved external symbol" usually means the linker is looking for a body for a function, but that body does not exist (or it can't find it).

Here, you have 3 functions which are declared in Tetrahedron that you did not provide a body for:
- metaObject
- qt_metacast
- qt_metacall


Since you did not explicitly prototype these functions in your class, I'm assuming the Q_OBJECT macro is prototyping them. If you do not know how to define them, I would try removing that macro from the class definition.
Last edited on
I got the same problem as the original poseter when I tested his code - but
it all went away when I put the tetrahedron stuff into it's own header and cpp file(s) as per normal .

((I don't know if the link posted by ne555 suggested doing just that very thing.))
@guestgulkan

Thanks man, that worked for me too!
Topic archived. No new replies allowed.