QMake issue - vtable

CodeLite installation/troubleshooting forum
ogee77
CodeLite Enthusiast
Posts: 22
Joined: Sat Mar 06, 2010 1:43 pm
Genuine User: Yes
IDE Question: C++
Contact:

QMake issue - vtable

Post by ogee77 »

Hi, first I want to say that CodeLite is really a great piece of work! I' ve been using it for quite a time now and it only proves it self better and better with every new release (actually with every new commit ;) ). I' ve been recently involved with Qt and wanted to set it up to work in CodeLite. However, the configuration gave me a hard time. When I try to compile a Qt which uses Q_OBJECT then 'undefined reference to vtable' occurs as if there were some virtual functions not implemented.

Build output:

----------Build Started--------
/bin/sh -c '"make" -j 2 -f "test_qt_wsp.mk"'
----------Building project:[ first3_qt - Debug ]----------
make[1]: Entering directory `/home/pawels/dev/test_qt/first3_qt'
make[1]: warning: -jN forced in submake: disabling jobserver mode.
/opt/qtsdk-2010.05/qt/bin/qmake -spec /opt/qtsdk-2010.05/qt/mkspecs/linux-g++ -o first3_qt.mk first3_qt.pro
make[1]: Leaving directory `/home/pawels/dev/test_qt/first3_qt'
make[1]: Entering directory `/home/pawels/dev/test_qt/first3_qt'
make[1]: warning: -jN forced in submake: disabling jobserver mode.
g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -I/opt/qtsdk-2010.05/qt/mkspecs/linux-g++ -I. -I/opt/qtsdk-2010.05/qt/include/QtCore -I/opt/qtsdk-2010.05/qt/include/QtGui -I/opt/qtsdk-2010.05/qt/include -I. -I. -o Debug/main.o main.cpp
g++ -Wl,-rpath,/opt/qtsdk-2010.05/qt/lib -o Debug/first3_qt Debug/main.o -L/opt/qtsdk-2010.05/qt/lib -lQtGui -lQtCore -lpthread
Debug/main.o: In function `AddressBook':
/home/pawels/dev/test_qt/first3_qt/main.cpp:21: undefined reference to `vtable for AddressBook'
/home/pawels/dev/test_qt/first3_qt/main.cpp:21: undefined reference to `vtable for AddressBook'
Debug/main.o: In function `~AddressBook':
/home/pawels/dev/test_qt/first3_qt/main.cpp:9: undefined reference to `vtable for AddressBook'
/home/pawels/dev/test_qt/first3_qt/main.cpp:9: undefined reference to `vtable for AddressBook'
collect2: ld returned 1 exit status
make[1]: *** [Debug/first3_qt] Error 1
make[1]: Leaving directory `/home/pawels/dev/test_qt/first3_qt'
make: *** [All] Error 2
----------Build Ended----------
0 errors, 0 warnings

My application is:

#include <QtGui>
#include <QWidget>

class QLabel;
class QLineEdit;
class QTextEdit;

class AddressBook : public QWidget
{
Q_OBJECT

public:
AddressBook(QWidget *parent = 0);
private:
QLineEdit *nameLine;
QTextEdit *addressText;
};


AddressBook::AddressBook(QWidget *parent)
: QWidget(parent)
{

}

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

AddressBook addressBook;
addressBook.show();

return app.exec();
return 0;

}

Makefile:

#############################################################################
# Makefile for building: Debug/first3_qt
# Generated by qmake (2.01a) (Qt 4.7.0) on: Fri Oct 15 00:35:58 2010
# Project: first3_qt.pro
# Template: app
# Command: /opt/qtsdk-2010.05/qt/bin/qmake -spec /opt/qtsdk-2010.05/qt/mkspecs/linux-g++ -o first3_qt.mk first3_qt.pro
#############################################################################

####### Compiler, tools and options

CC = gcc
CXX = g++
DEFINES = -DQT_GUI_LIB -DQT_CORE_LIB
CFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
CXXFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
INCPATH = -I/opt/qtsdk-2010.05/qt/mkspecs/linux-g++ -I. -I/opt/qtsdk-2010.05/qt/include/QtCore -I/opt/qtsdk-2010.05/qt/include/QtGui -I/opt/qtsdk-2010.05/qt/include -I. -I.
LINK = g++
LFLAGS = -Wl,-rpath,/opt/qtsdk-2010.05/qt/lib
LIBS = $(SUBLIBS) -L/opt/qtsdk-2010.05/qt/lib -lQtGui -lQtCore -lpthread
AR = ar cqs
RANLIB =
QMAKE = /opt/qtsdk-2010.05/qt/bin/qmake
TAR = tar -cf
COMPRESS = gzip -9f
COPY = cp -f
SED = sed
COPY_FILE = $(COPY)
COPY_DIR = $(COPY) -r
STRIP = strip
INSTALL_FILE = install -m 644 -p
INSTALL_DIR = $(COPY_DIR)
INSTALL_PROGRAM = install -m 755 -p
DEL_FILE = rm -f
SYMLINK = ln -f -s
DEL_DIR = rmdir
MOVE = mv -f
CHK_DIR_EXISTS= test -d
MKDIR = mkdir -p

####### Output directory

OBJECTS_DIR = Debug/

####### Files

SOURCES = main.cpp
OBJECTS = Debug/main.o
DIST = /opt/qtsdk-2010.05/qt/mkspecs/common/g++.conf \
/opt/qtsdk-2010.05/qt/mkspecs/common/unix.conf \
/opt/qtsdk-2010.05/qt/mkspecs/common/linux.conf \
/opt/qtsdk-2010.05/qt/mkspecs/qconfig.pri \
/opt/qtsdk-2010.05/qt/mkspecs/modules/qt_webkit_version.pri \
/opt/qtsdk-2010.05/qt/mkspecs/features/qt_functions.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/qt_config.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/exclusive_builds.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/default_pre.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/debug.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/default_post.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/warn_on.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/resources.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/uic.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/yacc.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/lex.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/qt.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/unix/thread.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/moc.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/include_source_dir.prf \
first3_qt.pro
QMAKE_TARGET = first3_qt
DESTDIR = Debug/
TARGET = Debug/first3_qt

first: all
####### Implicit rules

.SUFFIXES: .o .c .cpp .cc .cxx .C

.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"

.cc.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"

.cxx.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"

.C.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"

.c.o:
$(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"

####### Build rules

all: first3_qt.mk $(TARGET)

$(TARGET): $(OBJECTS)
@$(CHK_DIR_EXISTS) Debug/ || $(MKDIR) Debug/
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)

first3_qt.mk: first3_qt.pro /opt/qtsdk-2010.05/qt/mkspecs/linux-g++/qmake.conf /opt/qtsdk-2010.05/qt/mkspecs/common/g++.conf \
/opt/qtsdk-2010.05/qt/mkspecs/common/unix.conf \
/opt/qtsdk-2010.05/qt/mkspecs/common/linux.conf \
/opt/qtsdk-2010.05/qt/mkspecs/qconfig.pri \
/opt/qtsdk-2010.05/qt/mkspecs/modules/qt_webkit_version.pri \
/opt/qtsdk-2010.05/qt/mkspecs/features/qt_functions.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/qt_config.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/exclusive_builds.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/default_pre.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/debug.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/default_post.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/warn_on.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/resources.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/uic.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/yacc.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/lex.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/qt.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/unix/thread.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/moc.prf \
/opt/qtsdk-2010.05/qt/mkspecs/features/include_source_dir.prf
$(QMAKE) -spec /opt/qtsdk-2010.05/qt/mkspecs/linux-g++ -o first3_qt.mk first3_qt.pro
/opt/qtsdk-2010.05/qt/mkspecs/common/g++.conf:
/opt/qtsdk-2010.05/qt/mkspecs/common/unix.conf:
/opt/qtsdk-2010.05/qt/mkspecs/common/linux.conf:
/opt/qtsdk-2010.05/qt/mkspecs/qconfig.pri:
/opt/qtsdk-2010.05/qt/mkspecs/modules/qt_webkit_version.pri:
/opt/qtsdk-2010.05/qt/mkspecs/features/qt_functions.prf:
/opt/qtsdk-2010.05/qt/mkspecs/features/qt_config.prf:
/opt/qtsdk-2010.05/qt/mkspecs/features/exclusive_builds.prf:
/opt/qtsdk-2010.05/qt/mkspecs/features/default_pre.prf:
/opt/qtsdk-2010.05/qt/mkspecs/features/debug.prf:
/opt/qtsdk-2010.05/qt/mkspecs/features/default_post.prf:
/opt/qtsdk-2010.05/qt/mkspecs/features/warn_on.prf:
/opt/qtsdk-2010.05/qt/mkspecs/features/resources.prf:
/opt/qtsdk-2010.05/qt/mkspecs/features/uic.prf:
/opt/qtsdk-2010.05/qt/mkspecs/features/yacc.prf:
/opt/qtsdk-2010.05/qt/mkspecs/features/lex.prf:
/opt/qtsdk-2010.05/qt/mkspecs/features/qt.prf:
/opt/qtsdk-2010.05/qt/mkspecs/features/unix/thread.prf:
/opt/qtsdk-2010.05/qt/mkspecs/features/moc.prf:
/opt/qtsdk-2010.05/qt/mkspecs/features/include_source_dir.prf:
qmake: FORCE
@$(QMAKE) -spec /opt/qtsdk-2010.05/qt/mkspecs/linux-g++ -o first3_qt.mk first3_qt.pro

dist:
@$(CHK_DIR_EXISTS) Debug/first3_qt1.0.0 || $(MKDIR) Debug/first3_qt1.0.0
$(COPY_FILE) --parents $(SOURCES) $(DIST) Debug/first3_qt1.0.0/ && $(COPY_FILE) --parents main.cpp Debug/first3_qt1.0.0/ && (cd `dirname Debug/first3_qt1.0.0` && $(TAR) first3_qt1.0.0.tar first3_qt1.0.0 && $(COMPRESS) first3_qt1.0.0.tar) && $(MOVE) `dirname Debug/first3_qt1.0.0`/first3_qt1.0.0.tar.gz . && $(DEL_FILE) -r Debug/first3_qt1.0.0


clean:compiler_clean
-$(DEL_FILE) $(OBJECTS)
-$(DEL_FILE) *~ core *.core


####### Sub-libraries

distclean: clean
-$(DEL_FILE) $(TARGET)
-$(DEL_FILE) first3_qt.mk


check: first

/opt/qtsdk-2010.05/qt/bin/moc:
(cd $(QTDIR)/src/tools/moc && $(MAKE))

mocclean: compiler_moc_header_clean compiler_moc_source_clean

mocables: compiler_moc_header_make_all compiler_moc_source_make_all

compiler_rcc_make_all:
compiler_rcc_clean:
compiler_uic_make_all:
compiler_uic_clean:
compiler_image_collection_make_all: qmake_image_collection.cpp
compiler_image_collection_clean:
-$(DEL_FILE) qmake_image_collection.cpp
compiler_yacc_decl_make_all:
compiler_yacc_decl_clean:
compiler_yacc_impl_make_all:
compiler_yacc_impl_clean:
compiler_lex_make_all:
compiler_lex_clean:
compiler_moc_header_make_all:
compiler_moc_header_clean:
compiler_moc_source_make_all: main.moc
compiler_moc_source_clean:
-$(DEL_FILE) main.moc
main.moc: main.cpp \
/opt/qtsdk-2010.05/qt/bin/moc
/opt/qtsdk-2010.05/qt/bin/moc $(DEFINES) $(INCPATH) main.cpp -o main.moc

compiler_clean: compiler_moc_source_clean

####### Compile

Debug/main.o: main.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Debug/main.o main.cpp

####### Install

install: FORCE

uninstall: FORCE

FORCE:

Pro file:

##########################################
# codelite's qmake configuration: MyQMake
# codelite's qmake exec line :
##########################################
DESTDIR = /home/pawels/dev/test_qt/first3_qt/
TEMPLATE = app
CONFIG = release qt lex yacc uic resources warn_on precompile_header
MAKEFILE = /home/pawels/dev/test_qt/first3_qt/first3_qt.mk
OBJECTS_DIR = ./Debug
TARGET = ./Debug/first3_qt
INCLUDEPATH = .
QMAKE_CFLAGS_RELEASE = -g
QMAKE_CXXFLAGS_RELEASE = -g
DEFINES =
QMAKE_LFLAGS_RELEASE =
LIBS =
LIBS +=
LIBS +=
SOURCES = \
/home/pawels/dev/test_qt/first3_qt/main.cpp\

HEADERS = \

FORMS = \

YACCSOURCES = \

LEXSOURCES = \

RESOURCES = \

##########################################
# User section
##########################################

CONFIG += debug

Is if possible that qmake is not called at all?

I am on 32 bit machine running fedora 13.
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: QMake issue - vtable

Post by eranif »

Hi,

This is not really a codelite issue, but a QT issue:

When u run 'qmake' (codelite does that for you), qmake searches for Q_OBJECTS and other macros of QT in the sources. When it does find one, it generates a .moc file (which contains the missing functions that your linker complains about).
In your case, qmake does not generate the .moc file, since (it seems) that it will only generate a .moc file if you will attempt to include one.

Change your code to be (note that I added #include <main.moc> after the class declaration):

Code: Select all

#include <QtGui>
#include <QWidget>

class QLabel;
class QLineEdit;
class QTextEdit;

class AddressBook;
class AddressBook : public QWidget
{
	Q_OBJECT
public:
	AddressBook(QWidget *parent = 0);
private:
	QLineEdit *nameLine;
	QTextEdit *addressText;
};


AddressBook::AddressBook(QWidget *parent)
	: QWidget(parent)
{
}

#include <main.moc>

int main(int argc, char *argv[])
{
	QApplication app(argc, argv);
	AddressBook addressBook;
	addressBook.show();
	return app.exec();
}

And then right click on the project and rebuild it (it worked for. i.e. with your code I got the linking errors, after adding the #include <main.moc> I got the file main.moc to be generated)
Eran
Make sure you have read the HOW TO POST thread
ogee77
CodeLite Enthusiast
Posts: 22
Joined: Sat Mar 06, 2010 1:43 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: QMake issue - vtable

Post by ogee77 »

Thanks Eran, this solved the problem!
Post Reply