CMake for iOS: Adding Swift sources from CMake subdirectory. How?
-
wrote on 10 Jan 2023, 16:39 last edited by bogong 1 Oct 2023, 16:48
Hello all!
Trying to add Swift sources from CMake subdirectory and having this kind of reoubles:
ld: warning: Could not find or use auto-linked library 'swiftFoundation' ld: warning: Could not find or use auto-linked library 'swiftDarwin' ld: warning: Could not find or use auto-linked library 'swiftCore' ld: warning: Could not find or use auto-linked library 'swiftCoreGraphics' ld: warning: Could not find or use auto-linked library 'swiftObjectiveC' ld: warning: Could not find or use auto-linked library 'swiftCoreFoundation' ld: warning: Could not find or use auto-linked library 'swift_Concurrency' ld: warning: Could not find or use auto-linked library 'swiftDispatch' ld: warning: Could not find or use auto-linked library 'swiftCompatibility51' ld: warning: Could not find or use auto-linked library 'swiftCompatibilityConcurrency' Undefined symbols for architecture x86_64: "__swift_FORCE_LOAD_$_swiftCompatibilityConcurrency", referenced from: __swift_FORCE_LOAD_$_swiftCompatibilityConcurrency_$_ASwift in libASwift.a(aswiftiosswift.o) (maybe you meant: __swift_FORCE_LOAD_$_swiftCompatibilityConcurrency_$_ASwift) "__swift_FORCE_LOAD_$_swiftCompatibility51", referenced from: __swift_FORCE_LOAD_$_swiftCompatibility51_$_ASwift in libASwift.a(aswiftiosswift.o) (maybe you meant: __swift_FORCE_LOAD_$_swiftCompatibility51_$_ASwift) "__swift_FORCE_LOAD_$_swiftCoreGraphics", referenced from: __swift_FORCE_LOAD_$_swiftCoreGraphics_$_ASwift in libASwift.a(aswiftiosswift.o) (maybe you meant: __swift_FORCE_LOAD_$_swiftCoreGraphics_$_ASwift) "__swift_FORCE_LOAD_$_swiftDispatch", referenced from: __swift_FORCE_LOAD_$_swiftDispatch_$_ASwift in libASwift.a(aswiftiosswift.o) (maybe you meant: __swift_FORCE_LOAD_$_swiftDispatch_$_ASwift) "__swift_FORCE_LOAD_$_swiftCoreFoundation", referenced from: __swift_FORCE_LOAD_$_swiftCoreFoundation_$_ASwift in libASwift.a(aswiftiosswift.o) (maybe you meant: __swift_FORCE_LOAD_$_swiftCoreFoundation_$_ASwift) "value witness table for Builtin.UnknownObject", referenced from: full type metadata for ASwift.ASwiftIOSSwift in libASwift.a(aswiftiosswift.o) "__swift_FORCE_LOAD_$_swiftFoundation", referenced from: __swift_FORCE_LOAD_$_swiftFoundation_$_ASwift in libASwift.a(aswiftiosswift.o) (maybe you meant: __swift_FORCE_LOAD_$_swiftFoundation_$_ASwift) "nominal type descriptor for Swift._ContiguousArrayStorage", referenced from: _symbolic _____yypG s23_ContiguousArrayStorageC in libASwift.a(aswiftiosswift.o) "_swift_getObjCClassMetadata", referenced from: type metadata accessor for __C.NSString in libASwift.a(aswiftiosswift.o) "__swift_FORCE_LOAD_$_swiftObjectiveC", referenced from: __swift_FORCE_LOAD_$_swiftObjectiveC_$_ASwift in libASwift.a(aswiftiosswift.o) (maybe you meant: __swift_FORCE_LOAD_$_swiftObjectiveC_$_ASwift) "type metadata for Swift.String", referenced from: @objc ASwift.ASwiftIOSSwift.init() -> ASwift.ASwiftIOSSwift in libASwift.a(aswiftiosswift.o) "__swift_FORCE_LOAD_$_swiftDarwin", referenced from: __swift_FORCE_LOAD_$_swiftDarwin_$_ASwift in libASwift.a(aswiftiosswift.o) (maybe you meant: __swift_FORCE_LOAD_$_swiftDarwin_$_ASwift) "_swift_release", referenced from: @objc ASwift.ASwiftIOSSwift.init() -> ASwift.ASwiftIOSSwift in libASwift.a(aswiftiosswift.o) "Swift.print(_: Any..., separator: Swift.String, terminator: Swift.String) -> ()", referenced from: @objc ASwift.ASwiftIOSSwift.init() -> ASwift.ASwiftIOSSwift in libASwift.a(aswiftiosswift.o) "_swift_allocObject", referenced from: @objc ASwift.ASwiftIOSSwift.init() -> ASwift.ASwiftIOSSwift in libASwift.a(aswiftiosswift.o) "(extension in Foundation):__C.NSString.init(stringLiteral: Swift.StaticString) -> __C.NSString", referenced from: ASwift.ASwiftIOSSwift.mString() -> __C.NSString in libASwift.a(aswiftiosswift.o) @objc ASwift.ASwiftIOSSwift.mString() -> __C.NSString in libASwift.a(aswiftiosswift.o) "_swift_getTypeByMangledNameInContext", referenced from: ___swift_instantiateConcreteTypeFromMangledName in libASwift.a(aswiftiosswift.o) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
When adding Swift sources directly from top level project everything is working perfectly, here the published example of it. When trying to do the same from subdirectory - getting fail with error mentioned above.
When trying to build only subdirectory target in XCode - all is built, but trying to build whole project have fail.
What need to be added to the CMake file to build it properly?
In following logs somehow the main project doesn't see compiled object aswiftiosswift.o. The same CMake template used by me for adding libraray but without Swift code and all is working. In CMakeLists.tx in subdirectory added this parameters:
set_target_properties(${A_NAME_TARGET} PROPERTIES XCODE_ATTRIBUTE_SWIFT_OBJC_INTERFACE_HEADER_NAME "aswiftobjcinterface.h" XCODE_ATTRIBUTE_SWIFT_OBJC_BRIDGING_HEADER "${A_DIR_MODULE_ROOT}/aswiftbridging.h" XCODE_ATTRIBUTE_ENABLE_BITCODE "NO" XCODE_ATTRIBUTE_ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES "YES" XCODE_ATTRIBUTE_SWIFT_VERSION "5.0" )
-
wrote on 10 Jan 2023, 17:19 last edited by bogong 1 Oct 2023, 17:22
Solution for running swift code found. It's published here
But there are abnormal application behaviour. There are different errors in QtCreator and XCode.
In QtCreator this warnings:objc[8323]: Class QMacAutoReleasePoolTracker is implemented in both /Users/alexandr/Projects/arboreus/arboreus_examples/qt6/CMake/UsingSwift/build-UsingSwift_v2-Qt_6_2_7_for_iOS_Simulator/UsingSwift_v2_libraries/Swift/Debug-iphonesimulator/libASwift.dylib (0x1070b3348) and /Users/alexandr/Library/Developer/CoreSimulator/Devices/B8D2B6BB-1EB0-4549-BFCD-FB6FEBDD8587/data/Containers/Bundle/Application/1AFCE829-C5DF-451A-B6AF-6E37F0D17828/UsingSwift_v2.app/UsingSwift_v2 (0x1026f8e40). One of the two will be used. Which one is undefined. objc[8323]: Class KeyValueObserver is implemented in both /Users/alexandr/Projects/arboreus/arboreus_examples/qt6/CMake/UsingSwift/build-UsingSwift_v2-Qt_6_2_7_for_iOS_Simulator/UsingSwift_v2_libraries/Swift/Debug-iphonesimulator/libASwift.dylib (0x1070b3398) and /Users/alexandr/Library/Developer/CoreSimulator/Devices/B8D2B6BB-1EB0-4549-BFCD-FB6FEBDD8587/data/Containers/Bundle/Application/1AFCE829-C5DF-451A-B6AF-6E37F0D17828/UsingSwift_v2.app/UsingSwift_v2 (0x1026f8e90). One of the two will be used. Which one is undefined. objc[8323]: Class RunLoopModeTracker is implemented in both /Users/alexandr/Projects/arboreus/arboreus_examples/qt6/CMake/UsingSwift/build-UsingSwift_v2-Qt_6_2_7_for_iOS_Simulator/UsingSwift_v2_libraries/Swift/Debug-iphonesimulator/libASwift.dylib (0x1070b33e8) and /Users/alexandr/Library/Developer/CoreSimulator/Devices/B8D2B6BB-1EB0-4549-BFCD-FB6FEBDD8587/data/Containers/Bundle/Application/1AFCE829-C5DF-451A-B6AF-6E37F0D17828/UsingSwift_v2.app/UsingSwift_v2 (0x1026f8ee0). One of the two will be used. Which one is undefined. QML debugging is enabled. Only use this in a safe environment. QObject: Cannot create children for a parent that is in a different thread. (Parent is QQmlApplicationEngine(0x7ff7bfbdeed0), parent's thread is QThread(0x600003414220), current thread is QThread(0x600003404ac0) ASwift created ASwiftIOSObjC init ASwiftIOSObjC instance created ASwiftIOSObjC instance shared ASwiftIOSNative created ASwift initiated DBG:SYS 1673370544153 0x600003414220 "SwiftString" [int main(int, char **)]:[/Users/alexandr/Projects/arboreus/arboreus_examples/qt6/CMake/UsingSwift/UsingSwift_v2/main.cpp]:[0] WRN:SYS 1673370544363 0x600003414220 stale focus object 0x0 , doing manual update [virtual void QIOSInputContext::update(Qt::InputMethodQueries)]:[/Users/qt/work/qt/qtbase/src/plugins/platforms/ios/qiosinputcontext.mm]:[0]
On XCode this:
objc[8445]: Class QMacAutoReleasePoolTracker is implemented in both /Users/alexandr/Projects/arboreus/arboreus_examples/qt6/CMake/UsingSwift/build-UsingSwift_v2-Qt_6_2_7_for_iOS_Simulator/UsingSwift_v2_libraries/Swift/Debug-iphonesimulator/libASwift.dylib (0x10d05d348) and /Users/alexandr/Library/Developer/CoreSimulator/Devices/B8D2B6BB-1EB0-4549-BFCD-FB6FEBDD8587/data/Containers/Bundle/Application/D5EE0180-2C62-4471-8A02-213503AF57BC/UsingSwift_v2.app/UsingSwift_v2 (0x107c6ee40). One of the two will be used. Which one is undefined. objc[8445]: Class KeyValueObserver is implemented in both /Users/alexandr/Projects/arboreus/arboreus_examples/qt6/CMake/UsingSwift/build-UsingSwift_v2-Qt_6_2_7_for_iOS_Simulator/UsingSwift_v2_libraries/Swift/Debug-iphonesimulator/libASwift.dylib (0x10d05d398) and /Users/alexandr/Library/Developer/CoreSimulator/Devices/B8D2B6BB-1EB0-4549-BFCD-FB6FEBDD8587/data/Containers/Bundle/Application/D5EE0180-2C62-4471-8A02-213503AF57BC/UsingSwift_v2.app/UsingSwift_v2 (0x107c6ee90). One of the two will be used. Which one is undefined. objc[8445]: Class RunLoopModeTracker is implemented in both /Users/alexandr/Projects/arboreus/arboreus_examples/qt6/CMake/UsingSwift/build-UsingSwift_v2-Qt_6_2_7_for_iOS_Simulator/UsingSwift_v2_libraries/Swift/Debug-iphonesimulator/libASwift.dylib (0x10d05d3e8) and /Users/alexandr/Library/Developer/CoreSimulator/Devices/B8D2B6BB-1EB0-4549-BFCD-FB6FEBDD8587/data/Containers/Bundle/Application/D5EE0180-2C62-4471-8A02-213503AF57BC/UsingSwift_v2.app/UsingSwift_v2 (0x107c6eee0). One of the two will be used. Which one is undefined. QML debugging is enabled. Only use this in a safe environment. 2023-01-10 20:17:00.625965+0300 UsingSwift_v2[8445:177698] QObject: Cannot create children for a parent that is in a different thread. (Parent is QQmlApplicationEngine(0x7ff7ba667ed0), parent's thread is QThread(0x6000004341f0), current thread is QThread(0x600000435170) 2023-01-10 20:17:00.626156+0300 UsingSwift_v2[8445:177698] ASwift created ASwiftIOSSwift init 2023-01-10 20:17:00.626606+0300 UsingSwift_v2[8445:177698] ASwiftIOSObjC init 2023-01-10 20:17:00.626699+0300 UsingSwift_v2[8445:177698] ASwiftIOSObjC instance created 2023-01-10 20:17:00.626824+0300 UsingSwift_v2[8445:177698] ASwiftIOSObjC instance shared 2023-01-10 20:17:00.626921+0300 UsingSwift_v2[8445:177698] ASwiftIOSNative created 2023-01-10 20:17:00.627047+0300 UsingSwift_v2[8445:177698] ASwift initiated DBG:SYS 1673371020627 0x6000004341f0 "SwiftString" [int main(int, char **)]:[/Users/alexandr/Projects/arboreus/arboreus_examples/qt6/CMake/UsingSwift/UsingSwift_v2/main.cpp]:[0] 2023-01-10 20:17:00.733730+0300 UsingSwift_v2[8445:177698] Metal GPU Frame Capture Enabled 2023-01-10 20:17:00.733999+0300 UsingSwift_v2[8445:177698] Metal API Validation Enabled WRN:SYS 1673371020846 0x6000004341f0 stale focus object 0x0 , doing manual update [virtual void QIOSInputContext::update(Qt::InputMethodQueries)]:[/Users/qt/work/qt/qtbase/src/plugins/platforms/ios/qiosinputcontext.mm]:[0] ================================================================= Main Thread Checker: UI API called on a background thread: -[UIView layer] PID: 8445, TID: 177867, Thread name: QSGRenderThread, Queue name: com.apple.root.default-qos.overcommit, QoS: 0 Backtrace: 4 UsingSwift_v2 0x0000000106cf402a _ZL14layerForWindowP7QWindow + 122 5 UsingSwift_v2 0x0000000106cf3ed9 _ZN15QMetalSwapChain16surfacePixelSizeEv + 105 6 UsingSwift_v2 0x0000000106607b20 _ZN15QSGRenderThread13syncAndRenderEv + 624 7 UsingSwift_v2 0x0000000106609444 _ZN15QSGRenderThread3runEv + 292 8 UsingSwift_v2 0x0000000105bcbfd3 _ZZN14QThreadPrivate5startEPvENK3$_0clEv + 755 9 UsingSwift_v2 0x0000000105bcadfd _ZN12_GLOBAL__N_122terminate_on_exceptionIZN14QThreadPrivate5startEPvE3$_0EEvOT_ + 29 10 UsingSwift_v2 0x0000000105bcad8f _ZN14QThreadPrivate5startEPv + 95 11 libsystem_pthread.dylib 0x00007fff701cb4e1 _pthread_start + 125 12 libsystem_pthread.dylib 0x00007fff701c6f6b thread_start + 15 2023-01-10 20:17:00.877687+0300 UsingSwift_v2[8445:177867] [reports] Main Thread Checker: UI API called on a background thread: -[UIView layer] PID: 8445, TID: 177867, Thread name: QSGRenderThread, Queue name: com.apple.root.default-qos.overcommit, QoS: 0 Backtrace: 4 UsingSwift_v2 0x0000000106cf402a _ZL14layerForWindowP7QWindow + 122 5 UsingSwift_v2 0x0000000106cf3ed9 _ZN15QMetalSwapChain16surfacePixelSizeEv + 105 6 UsingSwift_v2 0x0000000106607b20 _ZN15QSGRenderThread13syncAndRenderEv + 624 7 UsingSwift_v2 0x0000000106609444 _ZN15QSGRenderThread3runEv + 292 8 UsingSwift_v2 0x0000000105bcbfd3 _ZZN14QThreadPrivate5startEPvENK3$_0clEv + 755 9 UsingSwift_v2 0x0000000105bcadfd _ZN12_GLOBAL__N_122terminate_on_exceptionIZN14QThreadPrivate5startEPvE3$_0EEvOT_ + 29 10 UsingSwift_v2 0x0000000105bcad8f _ZN14QThreadPrivate5startEPv + 95 11 libsystem_pthread.dylib 0x00007fff701cb4e1 _pthread_start + 125 12 libsystem_pthread.dylib 0x00007fff701c6f6b thread_start + 15 ================================================================= Main Thread Checker: UI API called on a background thread: -[UIView contentScaleFactor] PID: 8445, TID: 177867, Thread name: QSGRenderThread, Queue name: com.apple.root.default-qos.overcommit, QoS: 0 Backtrace: 4 UsingSwift_v2 0x0000000105d1d391 _ZNK10QIOSWindow16devicePixelRatioEv + 33 5 UsingSwift_v2 0x00000001068de7de _ZNK7QWindow16devicePixelRatioEv + 94 6 UsingSwift_v2 0x0000000106cf49b8 _ZN15QMetalSwapChain14createOrResizeEv + 2120 7 UsingSwift_v2 0x0000000106607c48 _ZN15QSGRenderThread13syncAndRenderEv + 920 8 UsingSwift_v2 0x0000000106609444 _ZN15QSGRenderThread3runEv + 292 9 UsingSwift_v2 0x0000000105bcbfd3 _ZZN14QThreadPrivate5startEPvENK3$_0clEv + 755 10 UsingSwift_v2 0x0000000105bcadfd _ZN12_GLOBAL__N_122terminate_on_exceptionIZN14QThreadPrivate5startEPvE3$_0EEvOT_ + 29 11 UsingSwift_v2 0x0000000105bcad8f _ZN14QThreadPrivate5startEPv + 95 12 libsystem_pthread.dylib 0x00007fff701cb4e1 _pthread_start + 125 13 libsystem_pthread.dylib 0x00007fff701c6f6b thread_start + 15 2023-01-10 20:17:00.930482+0300 UsingSwift_v2[8445:177867] [reports] Main Thread Checker: UI API called on a background thread: -[UIView contentScaleFactor] PID: 8445, TID: 177867, Thread name: QSGRenderThread, Queue name: com.apple.root.default-qos.overcommit, QoS: 0 Backtrace: 4 UsingSwift_v2 0x0000000105d1d391 _ZNK10QIOSWindow16devicePixelRatioEv + 33 5 UsingSwift_v2 0x00000001068de7de _ZNK7QWindow16devicePixelRatioEv + 94 6 UsingSwift_v2 0x0000000106cf49b8 _ZN15QMetalSwapChain14createOrResizeEv + 2120 7 UsingSwift_v2 0x0000000106607c48 _ZN15QSGRenderThread13syncAndRenderEv + 920 8 UsingSwift_v2 0x0000000106609444 _ZN15QSGRenderThread3runEv + 292 9 UsingSwift_v2 0x0000000105bcbfd3 _ZZN14QThreadPrivate5startEPvENK3$_0clEv + 755 10 UsingSwift_v2 0x0000000105bcadfd _ZN12_GLOBAL__N_122terminate_on_exceptionIZN14QThreadPrivate5startEPvE3$_0EEvOT_ + 29 11 UsingSwift_v2 0x0000000105bcad8f _ZN14QThreadPrivate5startEPv + 95 12 libsystem_pthread.dylib 0x00007fff701cb4e1 _pthread_start + 125 13 libsystem_pthread.dylib 0x00007fff701c6f6b thread_start + 15
Something relevant to the treads between Qt and Objective-C/Swift part.
But all is working for published project.
It looks weird. Is it kind of next one bug with Qt? Or something missing in my code?From what logs showing there are abnormal logger behaviour too while Swift object not created.
-
wrote on 10 Jan 2023, 17:41 last edited by
On physiscal device have this error:
dyld[613]: Library not loaded: @rpath/libASwift.dylib Referenced from: /private/var/containers/Bundle/Application/57A78A93-7DF0-4EAE-9441-EFCC3C26B451/UsingSwift_v2.app/UsingSwift_v2 Reason: tried: '/Users/alexandr/Projects/arboreus/arboreus_examples /qt6/CMake/UsingSwift/build-UsingSwift_v2-Qt_6_2_7_for_iOS/UsingSwift_v2_libraries/Swift/Debug-iphoneos/libASwift.dylib' (no such file), '/Users/alexandr/Projects/arboreus/arboreus_examples/qt6/CMake/UsingSwift/build-UsingSwift_v2-Qt_6_2_7_for_iOS/UsingSwi ft_v2_libraries/Swift/Debug-iphoneos/libASwift.dylib' (no such file), '/usr/local/lib/libASwift.dylib' (no such file), '/usr/lib/libASwift.dylib' (no such file) program received signal 6, thread:15ae4;00:0600000000000000;01:0100000000000000;02:302da26b01000000;03:9b00000000000000;04:3029a26b01000000;05:0000000000000000;06:0000000000000000;07:900e000000000000;08:2000000000000000;09:0900000000000000;0a:0100000000000000;0b:0a00000000000000;0c:0000000000000000;0d:3600000000000000;0e:7a40b06002000000;0f:0000000000000000;10:0902000000000000;11:54ee370a01000000;12:0000000000000000;13:0000000000000000;14:3029a26b01000000;15:9b00000000000000;16:302da26b01000000;17:0100000000000000;18:0600000000000000;19:0837a26b01000000;1a:0100000000000000;1b:0000000000000000;1c:0000000000000000;1d:0029a26b01000000;1e:88a3380a01000000;1f:c028a26b01000000;20:a047380a01000000;21:00100000;metype:5;mecount:2;medata:10003;medata:6;memory:0x16ba22900=1029a26b01000000bca3380a012a2bab;memory:0x16ba22910=5035a26b0100000028a8350a011f725d;
1/3