Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Using QtCore based IOS Framework in IOS Project
QtWS25 Last Chance

Using QtCore based IOS Framework in IOS Project

Scheduled Pinned Locked Moved Solved Mobile and Embedded
8 Posts 2 Posters 283 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fep29
    wrote on last edited by
    #1

    I was able to successfully generate an IOS Framework named messenger_core using CMakeLists.txt The core of the code is written in C++ and uses qxmpp and QtCore, QtNetwork, and QtXml. I build everything in Xcode. And get no errors.

    However when i try and import my messenger_core.framework into my IOS Front end app, set up all of the Header Searcg Paths and Framework Search Paths, System Search Paths, and library search paths. I stubbornly get the same error of:

    QtIOS2/6.8.2/ios/lib/QtCore.framework/Headers/qttypetraits.h:10:10 'optional' file not found

    in file included from
    qxmpp/src/base/QXmppLogger.h:9:
    in file included from
    qxmpp/src/base/QXmppGlobal.h:13:
    in file included from
    QtIOS2/6.8.2/ios/lib/QtCore.framework/Headers/QString:1:
    in file included from
    QtIOS2/6.8.2/ios/lib/QtCore.framework/Headers/qstring.h:14:
    in file included from
    QtIOS2/6.8.2/ios/lib/QtCore.framework/Headers/qchar.h:8:
    in file included from QtIOS2/6.8.2/ios/lib/QtCore.framework/Headers/qcompare.h:631:
    in file included from QtIOS2/6.8.2/ios/lib/QtCore.framework/Headers/qcomparehelpers.h:18:

    I have tried to set up my xcode build settings in my front end IOS to be identical to what is in my messenger_core.xcodeproj, messenger_core.pbproject, ive played with other linker flags. and everything else.

    One high level question i immediately have, is it it even possible to treat QtCore.framework as installed by the qt isntaller as a normal IOS framework that can just be embedded into a prjoect and used, or is everything done through CmakeLists.txt?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fep29
      wrote on last edited by
      #2

      As an addendum to this are there instructions out there to create a CMake configuration for a shared ios framework linking against static Qt6 libs to be embedded in an iOS app. Cause it really looks like just dragging and dropping QtIOS2/6.8.2/ios/lib/QtCore.framework into xcode doesnt work.

      only Qt frameworks im using are:

      QtCore.framework
      QtNetwork.framework
      QtNetwork.framework

      As used by my qxmpp framework

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fep29
        wrote on last edited by fep29
        #3

        CMakeLists.txt used to generate static library messenger_core.framework looks like this:

        The consuming IOS Front end app results in error

        QtIOS2/6.8.2/ios/lib/QtCore.framework/Headers/qttypetraits.h:10:10 'optional' file not found

        when calling into messenger_core functions exposed by messenger_core *.h files.

        cmake_minimum_required(VERSION 3.5)
        project(messenger_core VERSION 1.0 LANGUAGES CXX)
        
        # iOS Toolchain
        set(CMAKE_SYSTEM_NAME "iOS")
        set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO") # Development; remove for release
        set(CMAKE_TOOLCHAIN_FILE "/path/to/ios-cmake/ios.toolchain.cmake") # Correct path
        set(CMAKE_IPHONEOS_DEPLOYMENT_TARGET "18.2") # Adjust as needed
        
        # Options for QT
        set (CMAKE_AUTOMOC ON)
        
        # Qt Locations
        set(CMAKE_PREFIX_PATH "/path/to/QtIOS/6.8.2/ios") # Correct path
        find_package(Qt6 COMPONENTS Core Network Xml REQUIRED)
        
        # QXmpp Locations
        set(QXMPP_INCLUDE_DIR "/path/to/qxmppStatic/qxmpp/src")
        set(QXMPP_LIBRARY_IOS "/path/to//qxmppStatic/qxmpp/build_ios/src/Debug-iphoneos/libQXmppQt6.a")
        
        set(HEADERS
            include/ChatClient.h
            include/XmppSignaler.h
        )
        
        set(SOURCES 
            src/ChatClient.cpp
            src/MessengerCLI.cpp
            src/XmppSignaler.cpp
        )
        
        # Create a STATIC library (or SHARED if needed)
        add_library(messenger_core SHARED
            ${HEADERS}
            ${SOURCES}
        )
        
        #link
        target_link_libraries(messenger_core
            PUBLIC
            ${QXMPP_LIBRARY_IOS} # Explicitly link QXmpp - CRUCIAL
            Qt6::Core
            Qt6::Network
            Qt6::Xml
        )
        
        target_include_directories(messenger_core
            PUBLIC
            include
            ${QXMPP_INCLUDE_DIR}
            ${HEADERS}
        )
        
        
        target_compile_definitions(messenger_core PUBLIC QT_NO_KEYWORDS)
        
        # iOS Specific Settings
        set_target_properties(messenger_core PROPERTIES
            XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++17"
            PLATFORM "iphoneos"
            # Or for a static library: ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
            FRAMEWORK TRUE
            PUBLIC_HEADER "${HEADERS}"
            MACOSX_FRAMEWORK_IDENTIFIER "com.entity.messenger_core"
        )
        
        # Install the framework
        # It takes the compiled messenger_core target (which Xcode has built) and creates 
        # the .framework bundle.  The .framework bundle is then copied to the Frameworks 
        # directory within the installation prefix.
        install(TARGETS messenger_core 
            FRAMEWORK DESTINATION .
            PUBLIC_HEADER
        )
        
        1 Reply Last reply
        0
        • F Offline
          F Offline
          fep29
          wrote on last edited by
          #4

          A more complete set of steps:

          1. Created a messenger_core.xcodeproj using a CMakeLists.txt: As seen above

          2. Built the resulting project in xcode, and this generated a messenger_core.framework:

          tree messenger_core.framework
          messenger_core.framework
          ├── Headers
          │ ├── ChatClient.h
          │ └── XmppSignaler.h
          ├── Info.plist
          └── doost_messenger_core

          1. Create a clean new IOS App project from template.

          2. Imported messenger_core.framework into IOS App

          3. Update
            Header Search path:
            path/to/qxmppStatic/qxmpp/src

          System Header Search Path:
          /path/to/QtIOS/6.8.2/ios/lib/QtCore.framework/Headers
          /path/to/QtIOS/6.8.2/ios/mkspecs/macx-ios-clang
          /path/to/QtIOS2/6.8.2/ios/include

          Library Search Path:
          /path/to/qxmppStatic/qxmpp/build_ios/src/Debug-iphoneos #where libQXmppQt6.a resides

          I have embedded the QtCore, QtNetwork, QtXml frameworks into the "Frameworks, Libraries, and Embedded Content" section of xcode, and ordered them correctly in build phases.

          Getting error out of the basic IOS Executable front end when calling into messenger_core.framework functions:

          QtIOS2/6.8.2/ios/lib/QtCore.framework/Headers/qttypetraits.h:10:10 'optional' file not found

          1 Reply Last reply
          0
          • jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Try to set C++17 like this:

            set(CMAKE_CXX_STANDARD 17)
            

            std::optional requires C++17.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • F Offline
              F Offline
              fep29
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • F Offline
                F Offline
                fep29
                wrote on last edited by fep29
                #7

                @jsulm thank you so much for the reply. The messenger_core framework builds fine. and yes it is set to C++17.

                Its the consuming iOS front end executable that consumes the messenger_core.framework that is failing with above error. And i did indeed make sure to check that consuming iOS project uses C++17. I also tried GNU++20 with the same error.

                I think one question that i have been struggle to get answered is can i even treat QtCore.framework, QtXml.framework, etc. (as installed here by the qt installer)

                /path/to/Qt/6.8.2/ios/lib
                

                like a normal IOS Framework and just embed it straight into Xcode?

                Pardon the messiness of this post. I was still trying to wrap my mind around the situation as I was posting the question.

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  fep29
                  wrote on last edited by
                  #8

                  Solved. There is a difference in file extensions between objective-c and objective-c++ one is *.m other is *.mm I was calling C++ from a .m file. and that caused the error.

                  1 Reply Last reply
                  0
                  • F fep29 has marked this topic as solved on

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved