我正在尝试使用waf构建我的项目。项目已正确编译,但存在一些链接错误。它无法链接到Resources文件(.qrc文件)
main.cpp.1.o:在函数
main': /home/sobingt/project/masterdetail/build/../main.cpp:20: undefined reference to
中qInitResources_masterdetail()'
WAF输出--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,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 -> 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文件
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',
)
树结构
├── 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
我知道这一定是个愚蠢的错误。请帮忙。 链接到Question posted in qtcentre 我知道这一定是个愚蠢的错误。请帮忙。链接到问题发布在qtcentre
我正在尝试的解决方案: 我在包含Q_OBJECT宏的所有头文件(或源文件)上运行moc。
moc -o moc_something.cpp something.h
然后将moc_something.cpp添加到正在构建的源中。
我正在尝试资源编译器:
rcc -o masterdetail.cpp masterdetail.qrc
然后必须将masterdetail.cpp添加到正在构建的源中。
我认为以上是由qmake自动完成的......我正在手动编译以试图找到合适的解决方案
答案 0 :(得分:2)
将cpp文件末尾的moc文件手动添加到带有标题的所有cpp文件,即mainwindow.cpp add
#include "mainwindow.moc"
并在编译器标志中包含-DWAF = 1
答案 1 :(得分:0)
似乎waf没有收集moc文件。根据waf docs,尝试添加这样的东西:
from waflib.TaskGen import feature, before_method, after_method
@feature('cxx')
@after_method('process_source')
@before_method('apply_incpaths')
def add_includes_paths(self):
incs = set(self.to_list(getattr(self, 'includes', '')))
for x in self.compiled_tasks:
incs.add(x.inputs[0].parent.path_from(self.path))
self.includes = list(incs)
process_source
应该处理moc文件处理