QtCreator for iOS: How to deploy a dylib shared library with my application

人盡茶涼 提交于 2019-12-04 17:22:10

1) In your library project make sure your dylibs have installname @rpath/mylib.dylib or such. E.g. by adding QMAKE_SONAME_PREFIX = @rpath to your library .pro file.
(You can check by looking at the first line of otool -L /path/to/libmylib.dylib. If the library is a prebuilt 3rdparty one, change it with install_name_tool -id @rpath/libmylib.dylib)

2) add the following to the application .pro file

# link to the lib:
LIBS += -L../mylib -lmylib
# make the app find the libs:
QMAKE_RPATHDIR = @executable_path/Frameworks
# deploy the libs:
mylib.files = $$OUT_PWD/mylib/libmylib.1.dylib
mylib.path = Frameworks
QMAKE_BUNDLE_DATA += mylib

I came up with a workaround for that, in case it could help anyone.

  • Build your library statically instead of dynamically (replace CONFIG += shared by CONFIG += staticlib

  • Now, compiler will generate *.a files instead of *.dylib, You must use this extension when linking libraries (replace LIBS += myLib.dylib by LIBS += myLib.a)

  • If your library was only linked by a program, you are done

  • If your library, let's call it (A), was used by another library (B), then (B) should not link with it anymore (No LIB flag in B.pro). Only the top level program will link with all your static libraries.

With this approach, I could deploy a program using 15 libraries on an iPhone with QtCreator.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!