wang-bin / QtAV

A cross-platform multimedia framework based on Qt and FFmpeg. 基于Qt和FFmpeg的跨平台高性能音视频播放框架. Recommand to use new sdk https://github.com/wang-bin/mdk-sdk
http://qtav.org
3.99k stars 1.51k forks source link

Static link and Qt Integration #368

Closed Ligverd closed 9 years ago

Ligverd commented 9 years ago

With static linking climbed some errors. this patch of their rights

diff --git a/QtAV.pro b/QtAV.pro
index b1406c7..832bd2f 100644
diff --git a/qml/libQmlAV.pro b/qml/libQmlAV.pro
index f73012c..d9869e7 100644
--- a/qml/libQmlAV.pro
+++ b/qml/libQmlAV.pro
@@ -4,8 +4,12 @@ TARGET = QmlAV
 QT += quick qml
 CONFIG *= qmlav-buildlib

+URI = QtAV
+QMAKE_MOC_OPTIONS += -Muri=$$URI
+
+
 #var with '_' can not pass to pri?
-STATICLINK = 0
+STATICLINK = 0
 PROJECTROOT = $$PWD/..
 !include($$PROJECTROOT/src/libQtAV.pri): error("could not find libQtAV.pri")
 !include(libQmlAV.pri): error("could not find libQmlAV.pri")
diff --git a/qml/qmldir b/qml/qmldir
index 9cc9001..4224db8 100644
--- a/qml/qmldir
+++ b/qml/qmldir
@@ -1,5 +1,5 @@
 module QtAV
 plugin QmlAV
-classname QMLAVModule
+classname QtAVQmlPlugin
 typeinfo plugins.qmltypes
 Video 1.3 Video.qml
diff --git a/src/libQtAV.pri b/src/libQtAV.pri
index f88eb9c..ea1b480 100644
diff --git a/src/libQtAV.pro b/src/libQtAV.pro
index 71a3f5a..ee0f541 100644
diff --git a/widgets/libQtAVWidgets.pro b/widgets/libQtAVWidgets.pro
index 946fabf..201acd5 100644

with static linking sdk_install/uninstall.sh trying to work with the .so files and it is necessary to .a I copied manually

wang-bin commented 9 years ago

QMAKE_MOC_OPTIONS += -Muri=$$URI what does this mean? I can't find out how qmake deal with this.

-classname QMLAVModule
+classname QtAVQmlPlugin

what's the difference?

Ligverd commented 9 years ago

1) without this, when the application starts QtQuick will swear static plugin for module “QtQuick” with name “QtAV:: QtAVQmlPlugin” has no metadata URI

I spent a lot of time to understand what the problem is

URI = QtAV
QMAKE_MOC_OPTIONS += -Muri=$$URI

http://qt-project.org/forums/viewthread/38438

2) with static linking Qt and QtAV QtCreator when building the target application creates two files appname_qml_plugin_import.cpp and appname_plugin_import.cpp

// This file is autogenerated by qmake. It imports static plugin classes for
// static plugins used by QML imports.
#include <QtPlugin>
Q_IMPORT_PLUGIN(QtQuick2Plugin)
Q_IMPORT_PLUGIN(QtQuick2WindowPlugin)
Q_IMPORT_PLUGIN(QtQuickControlsPlugin)
Q_IMPORT_PLUGIN(QtAVQmlPlugin)   <-- Q_IMPORT_PLUGIN(QMLAVModule) 
Q_IMPORT_PLUGIN(QMultimediaDeclarativeModule)
Q_IMPORT_PLUGIN(QtQuickLayoutsPlugin)

i.e. trying to link statically plugins. ld looks for a class named qt_static_plugin_CALSSNAME() actually libQmlAV.a present ad qt_static_plugin_QtAVQmlPlugin() and searched classname qt_static_plugin_QMLAVModule() the result is that the linker complains undefined symbol

explained how could

in QtAV/qml/plugin.cpp

class QtAVQmlPlugin : public QQmlExtensionPlugin
{
    Q_OBJECT
Ligverd commented 9 years ago

forgot to write Qt 5.4 QtCreator 3.2.2

wang-bin commented 9 years ago

you are right. thanks for your explanation. are you testing iOS?

Ligverd commented 9 years ago

iOS unfortunately not tested, but plan to try it. I'll write how you try.

wang-bin commented 9 years ago

QtAV frameworks build for iOS should be fine now. player & QMLPlayer have some strange build errors, the solution now is build QtAV sdk frameworks first and run sdk_install.sh, then modify player.pro for example in like this https://github.com/wang-bin/QtAV/wiki/Use-QtAV-In-Your-Projects. I have tested on simulator and works fine iOS