PDA

View Full Version : Building a QT project with WAF



learningqt
16th March 2012, 06:05
I am trying to building my project using waf.The Project is complied properly but there is some link error.Its fails to link to with the Resources file (.qrc file)


main.cpp.1.o: In function main': /home/sobingt/project/masterdetail/build/../main.cpp:20: undefined reference toqInitResources_masterdetail()'

WAF output --zones=deps


sobingt@tuneb03-System-Product-Name:~/projects/masterdetail$ ./waf --zones=deps
Waf: Entering directory `/home/sobingt/projects/masterdetail/build'
10:49:34 deps deps for [/home/sobingt/projects/masterdetail/main.cpp]: [/home/sobingt/projects/masterdetail/mainwindow.h, /home/sobingt/projects/masterdetail/listmodel.h, /home/sobingt/projects/masterdetail/cache.h, /home/sobingt/projects/masterdetail/tablemodel.h, /home/sobingt/projects/masterdetail/mytablemodel.h]; unresolved ['QApplication', 'QPalette', 'QPixmap', 'QSplashScreen', 'qthread.h', 'boost/scoped_ptr.hpp', 'QMainWindow', 'QModelIndex', 'QAbstractListModel', 'QList', 'QVariant', 'tr1/unordered_map', 'QAbstractTableModel', 'QStringList', 'iostream', 'sstream', 'vector']
10:49:34 deps scanner for qxx: main.cpp -> build/main.cpp.1.o returned [/home/sobingt/projects/masterdetail/mainwindow.h, /home/sobingt/projects/masterdetail/listmodel.h, /home/sobingt/projects/masterdetail/cache.h, /home/sobingt/projects/masterdetail/tablemodel.h, /home/sobingt/projects/masterdetail/mytablemodel.h] ['QApplication', 'QPalette', 'QPixmap', 'QSplashScreen', 'qthread.h', 'boost/scoped_ptr.hpp', 'QMainWindow', 'QModelIndex', 'QAbstractListModel', 'QList', 'QVariant', 'tr1/unordered_map', 'QAbstractTableModel', 'QStringList', 'iostream', 'sstream', 'vector']
[14/15] qxx: main.cpp -> build/main.cpp.1.o
[15/15] cxxprogram: build/main.cpp.1.o build/mainwindow.cpp.1.o build/masterdetail_rc.o build/cache.cpp.1.o build/listmodel.cpp.1.o build/model.cpp.1.o build/mysortfilterproxymodel.cpp.1.o build/mytablemodel.cpp.1.o build/song.cpp.1.o build/songitem.cpp.1.o build/songs.cpp.1.o build/tablemodel.cpp.1.o build/tableproxymodel.cpp.1.o -> build/app
main.cpp.1.o: In function `main':
/home/sobingt/projects/masterdetail/build/../main.cpp:20: undefined reference to `qInitResources_masterdetail()'
main.cpp.1.o: In function `~MainWindow':
/home/sobingt/projects/masterdetail/build/../mainwindow.h:22: undefined reference to `vtable for MainWindow'
/home/sobingt/projects/masterdetail/build/../mainwindow.h:22: undefined reference to `vtable for MainWindow'
mainwindow.cpp.1.o: In function `MainWindow':
/home/sobingt/projects/masterdetail/build/../mainwindow.cpp:22: undefined reference to `vtable for MainWindow'
/home/sobingt/projects/masterdetail/build/../mainwindow.cpp:22: undefined reference to `vtable for MainWindow'
mainwindow.cpp.1.o: In function `ListItem':
/home/sobingt/projects/masterdetail/build/../listmodel.h:14: undefined reference to `vtable for ListItem'
mainwindow.cpp.1.o: In function `MainWindow::tr(char const*, char const*)':
/home/sobingt/projects/masterdetail/build/../mainwindow.h:24: undefined reference to `MainWindow::staticMetaObject'
mainwindow.cpp.1.o: In function `SongItem':
/home/sobingt/projects/masterdetail/build/../songitem.h:17: undefined reference to `vtable for SongItem'
listmodel.cpp.1.o: In function `ListModel':
/home/sobingt/projects/masterdetail/build/../listmodel.cpp:7: undefined reference to `vtable for ListModel'
listmodel.cpp.1.o: In function `~ListModel':
/home/sobingt/projects/masterdetail/build/../listmodel.cpp:27: undefined reference to `vtable for ListModel'
mysortfilterproxymodel.cpp.1.o: In function `MySortFilterProxyModel':
/home/sobingt/projects/masterdetail/build/../mysortfilterproxymodel.cpp:4: undefined reference to `vtable for MySortFilterProxyModel'
mytablemodel.cpp.1.o: In function `MyTableModel':
/home/sobingt/projects/masterdetail/build/../mytablemodel.cpp:3: undefined reference to `vtable for MyTableModel'
tablemodel.cpp.1.o: In function `TableModel':
/home/sobingt/projects/masterdetail/build/../tablemodel.cpp:9: undefined reference to `vtable for TableModel'
collect2: ld returned 1 exit status
Waf: Leaving directory `/home/sobingt/projects/masterdetail/build'
Build failed
-> task failed (exit status 1):
{task 14658768: cxxprogram main.cpp.1.o,mainwindow.cpp.1.o,masterdetail_rc.o, cache.cpp.1.o,listmodel.cpp.1.o,model.cpp.1.o,myso rtfilterproxymodel.cpp.1.o,mytablemodel.cpp.1.o,so ng.cpp.1.o,songitem.cpp.1.o,songs.cpp.1.o,tablemod el.cpp.1.o,tableproxymodel.cpp.1.o -> app}
['/usr/bin/g++', 'main.cpp.1.o', 'mainwindow.cpp.1.o', 'masterdetail_rc.o', 'cache.cpp.1.o', 'listmodel.cpp.1.o', 'model.cpp.1.o', 'mysortfilterproxymodel.cpp.1.o', 'mytablemodel.cpp.1.o', 'song.cpp.1.o', 'songitem.cpp.1.o', 'songs.cpp.1.o', 'tablemodel.cpp.1.o', 'tableproxymodel.cpp.1.o', '-o', '/home/sobingt/projects/masterdetail/build/app', '-Wl,-Bstatic', '-Wl,-Bdynamic', '-lQtCore', '-lQtGui', '-lQtCore', '-lQtOpenGL', '-lQtGui', '-lQtCore', '-lQtSvg', '-lQtGui', '-lQtCore', '-lQtSql', '-lQtCore', '-lQtUiTools', '-lQtXml', '-lQtCore', '-lQtScript', '-lQtCore']

wscript file


VERSION='0.0.1'
APPNAME='qt4_test'

top = '.'
out = 'build'

def options(opt):
opt.load('compiler_cxx qt4')

def configure(conf):
conf.load('compiler_cxx qt4')
conf.env.append_value('CXXFLAGS', ['-g']) # test

def build(bld):
def build(bld):
bld(
features = 'qt4 cxx',
uselib = 'QTCORE QTGUI QTOPENGL QTSVG QWIDGET QTSQL QTUITOOLS QTSCRIPT',
includes = bld.env.INCLUDES_QTGUI,
source = 'mainwindow.cpp masterdetail.qrc cache.cpp listmodel.cpp model.cpp mysortfilterproxymodel.cpp mytablemodel.cpp song.cpp songitem.cpp songs.cpp tablemodel.cpp tableproxymodel.cpp',
target = 'mainwindow.o',
)
bld(
features = 'qt4 cxx cxxprogram',
uselib = 'QTCORE QTGUI QTOPENGL QTSVG QWIDGET QTSQL QTUITOOLS QTSCRIPT',
includes = bld.env.INCLUDES_QTGUI,
source = 'main.cpp',
target = 'app',
use = 'mainwindow.o',

)

project file structure


├── build
│ ├── c4che
│ │ ├── build.config.py
│ │ └── _cache.py
│ ├── config.log
│ ├── main.cpp.1.o
│ ├── masterdetail_rc.cpp
│ └── masterdetail_rc.o
├── cache.cpp
├── cache.h
├── images
│ ├── betaLogo.png
│ ├── exitButton.gif
│ ├── icon.png
│ ├── image.png
│ ├── mas.png
│ ├── play.png
│ ├── saveButton.png
│ ├── stopbutton.png
│ └── stop.png
├── listmodel.cpp
├── listmodel.h
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── Makefile
├── masterdetail64.png
├── masterdetail80.png
├── masterdetail.desktop
├── masterdetail_harmattan.desktop
├── masterdetail.pro
├── masterdetail.pro.user
├── masterdetail.qrc
├── masterdetail.svg
├── model.cpp
├── model.h
├── mysortfilterproxymodel.cpp
├── mysortfilterproxymodel.h
├── mytablemodel.cpp
├── mytablemodel.h
├── repository.db
├── song.cpp
├── song.h
├── songitem.cpp
├── songitem.h
├── songs.cpp
├── songs.h
├── tablemodel.cpp
├── tablemodel.h
├── tableproxymodel.cpp
├── tableproxymodel.h
├── tableUnit.cpp
├── waf
├── waf-1.6.11
├── wscript

ChrisW67
16th March 2012, 06:24
Where does your build process run rcc on the qrc file and include the result into the sources to be built?
Where does your build process run moc on the header files and include the result into the sources to be built?

learningqt
16th March 2012, 06:52
i didnot get you? You want me to also put the the source codes...i am not using moc.....i am a newbie so sorry if i wrote something stupid

Added after 6 minutes:

The error is during linking it to a executable object app

cxxprogram: build/main.cpp.2.o build/mainwindow.cpp.1.o build/masterdetail_rc.o build/cache.cpp.1.o build/listmodel.cpp.1.o build/model.cpp.1.o build/mysortfilterproxymodel.cpp.1.o build/mytablemodel.cpp.1.o build/song.cpp.1.o build/songitem.cpp.1.o build/songs.cpp.1.o build/tablemodel.cpp.1.o build/tableproxymodel.cpp.1.o -> build/app

main.cpp

#include <QApplication>

#include <QPalette>
#include <QPixmap>
#include <QSplashScreen>
#include <qthread.h>
#include "boost/scoped_ptr.hpp"
#include "mainwindow.h"

class I : public QThread
{
public:
static void sleep(unsigned long secs) {
QThread::sleep(secs);
}
};

int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(masterdetail);

QApplication app(argc, argv);

QPixmap pixmap(":/images/betaLogo.png");
QSplashScreen splash(pixmap);
splash.show();
splash.showMessage("Loading...");
qApp->processEvents();
I::sleep(2);//delay 2 sec
QPalette pal = app.palette();
pal.setColor(QPalette::Window, Qt::AA_MacPluginApplication);
app.setPalette(pal);

MainWindow window("artists", "albums");
window.show();
splash.finish(&window);//Makes the splash screen wait until the widget mainWin is displayed
return app.exec();
}

Added after 8 minutes:

how do i use the Resource Compiler (rcc) output...the .rcc file

i just used

rcc -binary masterdetail.qrc -o masterdetail.rcc

ChrisW67
16th March 2012, 07:15
You need to run moc on any header (or source) file containing a Q_OBJECT macro. Not doing this is the source of all the "vtable" errors in your original post.


moc -o moc_something.cpp something.h

and then the moc_something.cpp has to be added to the sources being built.

The resource compiler:


rcc -o something.cpp something.qrc

and then the something.cpp has to be added to the sources being built.

I am sure the qt4 support of WAF has some way of doing this for you, but I do not propose to learn WAF just to find out.