Building a Qt library for iOS



  • Hi

    We're having trouble linking a Qt library with a simple iOS application. We can build a complete iOS application using the Qt framework. Now we would like to share a library built upon Qt with a third party developer, in charge of the iOS app interface, without sharing source code.

    Is this possible with the current version of Qt-Creator and related tools ?

    The library can be static or shared and have a C-wrapper interface if needed. It needs access to the Qt multimedia modules however.

    So far, our attempts have failed with problem linking the library with the iOS executable. Before searching more in depth for a solution, we would like to know if this is possible at all.

    Thanks in advance for any help on the subject.

    Julien



  • Technically it's possible.
    If you don't find any solution, try to share here details of your process and errors.



  • I created a library project with QtCreator,

    pro file:

    @
    QT -= gui

    TARGET = mylib
    TEMPLATE = lib
    CONFIG += staticlib

    SOURCES += mylib.cpp

    HEADERS += mylib.h
    unix {
    target.path = /usr/lib
    INSTALLS += target
    }@

    header:
    @
    #ifndef MYLIB_H
    #define MYLIB_H

    class Mylib
    {
    public:
    Mylib() {}
    int integer ();
    const char* text ();
    };

    #endif@

    source:

    @
    #include "mylib.h"

    int Mylib::integer () { return 747; }

    #include <QtCore/QString>

    const char *Mylib::text()
    {
    static QString mt ("my text");
    return mt.toLatin1().constData();
    }
    @

    The compilation is OK and a "libmylib.a" file is created for iphoneos_clang_Qt_5_3.

    In XCODE I open a classic project for iPhone as "hello word". I add the static library "libmylib.a" and the header path for "mylib.h" in the project.

    After build the linker find an error:

    Undefined symbols for architecture armv7:
    "std::bad_alloc::bad_alloc()", referenced from:
    qBadAlloc() in libQt5Core.a(qglobal.o)
    QVector<QList<bool ()(void*)> >::reallocData(int, int, QFlagsQArrayData::AllocationOption) in libQt5Core.a(qglobal.o)
    ld: symbol(s) not found for architecture armv7
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    please how to solve this trouble? Thank's



  • It seems that libmylib.a needs an additional library to get linked that you not included into into the project using libmylib.a

    Consider that everytime you link against a static library you also need to include all other libraries that the static library needs, because the static library is just object files into an archive and hence, the linker has to resolve all symbols otherwise it fails.

    So, look at the linker options inserted by the Qt project creating the libmylib.a and try to find out what it's missing into the project using libmylib.a



  • ok I found the solution: in "build settings" from Xcode project in "Apple LLVM 5.1 - language - C++" section in "C++ standard library" line add "libc++" option

    thank's


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.