0

我有一个由两种产品组成的 .pro 项目:

播放器.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版本。


我写的是这样的:

播放器.qbs

Project {
    references: [
        "mediaplayer/MediaPlayer.qbs",
        "imageplayer/ImagePlayer.qbs",
    ]
}

媒体播放器.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", ]
    }
    <...>
}

图像播放器.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", ]
    }
    <...>
}

媒体播放器.h

#include "MediaPlayer_global.h"
#include "MediaPlayerInterface.h"

class MEDIAPLAYERSHARED_EXPORT MediaPlayer : public QWidget, public MediaPlayerInterface
{
    Q_OBJECT
    Q_INTERFACES(MediaPlayerInterface)
    <...>
}

图像播放器.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)

有人知道出了什么问题吗?

4

1 回答 1

0

这部分看起来很可疑:

Export {
    // ...
    cpp.defines: [ product.name.toUpperCase() + "_LIBRARY", ]
}

您不太可能真的想要导出此定义,因为它可能控制库的头文件之一中某些 EXPORT 预处理器标记的值(我不能肯定地说,因为我不知道您的项目)。只需从导出项目中删除此行。

于 2017-06-16T15:47:16.370 回答