Hello all!
My project written with C++ and CMake for iOS. It's using Swift implementation via Objective-C/ObjectiveC++. This project devided on modules via CMake add_subdirectory() functionality. When Swift/Objective-C/Objective-C++ sources attached to the Main project - all is working perfectly. But when trying to add Swift sources in subdirectory have troubles with it:
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)
What's missed by me?
When using in Main the CMake settings looks like:
set_target_properties(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"
)
When adding the same settings in subdirectory CMake file then nothing is working. What is the cause of this error?