Qt 插件:从 qmake 到 qbs。联动错误
Posted
技术标签:
【中文标题】Qt 插件:从 qmake 到 qbs。联动错误【英文标题】:Qt plugin: From qmake to qbs. Linkage error 【发布时间】:2017-05-26 08:38:06 【问题描述】:我有一个包含两个产品的 .pro 项目:
player.pro
TEMPLATE = subdirs
SUBDIRS = mediaplayer \
imageplayer
imageplayer.depends = mediaplayer
madiaplayer.pro - dll 库
TEMPLATE = lib
DEFINES += MEDIAPLAYER_LIBRARY
HEADERS = MediaPlayer_global.h \ <...>
<...>
imageplayer.pro - qt 插件
TEMPLATE = lib
CONFIG += plugin
LIBS *= -L<path to mediaplayer dll>
INCLUDEPATH *= mediaplayer \ <...>
DEPENDPATH *= $$INCLUDEPATH
<...>
它工作正常。但是现在我需要qbs版本。
我写的是这样的:
player.qbs
Project
references: [
"mediaplayer/MediaPlayer.qbs",
"imageplayer/ImagePlayer.qbs",
]
MediaPlayer.qbs
MediaPlayer
Group
qbs.install: true
fileTagsFilter: "dynamiclibrary"
cpp.includePaths: product.sourceDirectory
cpp.defines: [ product.name.toUpperCase() + "_LIBRARY", ]
Export
cpp.includePaths: product.sourceDirectory
cpp.defines: [ product.name.toUpperCase() + "_LIBRARY", ]
<...>
ImagePlayer.qbs
ImagePlayer
Depends name: "MediaPlayer"
Export Depends name: "MediaPlayer"
Group
qbs.install: true
fileTagsFilter: "dynamiclibrary"
cpp.includePaths: product.sourceDirectory
cpp.defines: [ product.name.toUpperCase() + "_LIBRARY", ]
Export
cpp.includePaths: product.sourceDirectory
cpp.defines: [ product.name.toUpperCase() + "_LIBRARY", ]
<...>
MediaPlayer.h
#include "MediaPlayer_global.h"
#include "MediaPlayerInterface.h"
class MEDIAPLAYERSHARED_EXPORT MediaPlayer : public QWidget, public MediaPlayerInterface
Q_OBJECT
Q_INTERFACES(MediaPlayerInterface)
<...>
ImagePlayer.h
#include "../mediaplayer/MediaPlayer.h"
class ImagePlayer : public MediaPlayer
Q_OBJECT
Q_INTERFACES(MediaPlayerInterface)
Q_PLUGIN_METADATA(IID "org.geeksoft.qt.MediaPlayerInterface")
<...>
但是...我得到了一个非常不清楚的错误结果(它是 ImagePlayer.dll 链接阶段):
ImagePlayer.cpp.obj: 未解析的外部符号“public: static struct QMetaObject const MediaPlayer::staticMetaObject” (?staticMetaObject@MediaPlayer@@2UQMetaObject@@B)
moc_ImagePlayer.cpp.obj: 未解析的外部符号“public: static struct QMetaObject const MediaPlayer::staticMetaObject”(?staticMetaObject@MediaPlayer@@2UQMetaObject@@B)
有人知道出了什么问题吗?
【问题讨论】:
【参考方案1】:这部分看起来很可疑:
Export
// ...
cpp.defines: [ product.name.toUpperCase() + "_LIBRARY", ]
您不太可能真的想导出此定义,因为它可能控制库的头文件之一中某些 EXPORT 预处理器标记的值(我不能肯定地说,因为我不知道您的项目)。只需从 Export 项中删除此行即可。
【讨论】:
以上是关于Qt 插件:从 qmake 到 qbs。联动错误的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Qt 代码中访问 Qt 构建系统项目 (QBS) 变量