开发者

Is there a way to package a dynamic library in the application binary?

Hi I am developing a Qt application that uses a plugin (dynamic library) and I was wondering if there was a way I could build the application and library in one file (maybe using the 开发者_开发百科QResource feature?)


Qt supports linking plugins statically to your application. See the documentation.

You use the Q_IMPORT_PLUGIN() macro in your code like so:

#include <QApplication>
#include <QtPlugin>

Q_IMPORT_PLUGIN(qjpeg)

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    ...
    return app.exec();
}

You also need to list the plugins in QTPLUGIN in your .pro file:

QTPLUGIN += qjpeg

You may also need to build a static version of Qt yourself - not sure if the prebuilt versions contain static libraries (I don't use the prebuilt code).


You want an application like "DLL to Lib" that will convert your DLL file to a static library. Then you'd link with the .lib file instead of the DLL and you're all set. You can download a trial of one product here:

http://www.binary-soft.com/download.htm


When you do this, make sure not to violate the license of the library. If the library isn't available as a static library, it might be under the LGPL (or even GPL). Linking statically in either case would violate the license unless you are releasing your software also under the GPL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜