从客观c项目调用独立项目中的swift文件。 Apple Mach-o Linker error

问题描述:

我们有一个传统的iOS目标C应用程序。我们想要添加“快速”功能。创建一个单独的“可可触摸框架”项目,从“目标C”项目中引用它。当我尝试调用/我收到此错误初始化任何在迅速的方法,由目标C从客观c项目调用独立项目中的swift文件。 Apple Mach-o Linker error

Ld /Users/teeboy/Library/Developer/Xcode/DerivedData/super-aybvkjtipygrszeyqsnbmtglaaqi/Build/Products/Debug-iphonesimulator/super.app/super normal x86_64 cd /Users/teeboy/iWorkbench/super export IPHONEOS_DEPLOYMENT_TARGET=10.0 export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk -L/Users/teeboy/Library/Developer/Xcode/DerivedData/super-aybvkjtipygrszeyqsnbmtglaaqi/Build/Products/Debug-iphonesimulator -F/Users/teeboy/Library/Developer/Xcode/DerivedData/super-aybvkjtipygrszeyqsnbmtglaaqi/Build/Products/Debug-iphonesimulator -F/Users/teeboy/iWorkbench/super -filelist /Users/teeboy/Library/Developer/Xcode/DerivedData/super-aybvkjtipygrszeyqsnbmtglaaqi/Build/Intermediates/super.build/Debug-iphonesimulator/super.build/Objects-normal/x86_64/super.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -mios-simulator-version-min=10.0 -dead_strip -Xlinker -object_path_lto -Xlinker /Users/teeboy/Library/Developer/Xcode/DerivedData/super-aybvkjtipygrszeyqsnbmtglaaqi/Build/Intermediates/super.build/Debug-iphonesimulator/super.build/Objects-normal/x86_64/super_lto.o -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -ObjC -all_load -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/teeboy/Library/Developer/Xcode/DerivedData/super-aybvkjtipygrszeyqsnbmtglaaqi/Build/Intermediates/super.build/Debug-iphonesimulator/super.build/super.app.xcent -lz -lPatientSearch -framework MapKit -framework ZipArchive -framework QuartzCore -lMobuleMenuCell -framework OCMockitoIOS -framework Security -lModuleNavigation -lToDoList -framework CoreData -lPatientChart -framework CoreText -framework Crashlytics -framework CoreLocation -lVisitNotes -lDataAccess -lDashboard -framework MobileCoreServices -framework SystemConfiguration -lframework -lsuperCommon -framework UIKit -framework OCHamcrestIOS -framework Foundation -framework CoreGraphics -Xlinker -dependency_info -Xlinker /Users/teeboy/Library/Developer/Xcode/DerivedData/super-aybvkjtipygrszeyqsnbmtglaaqi/Build/Intermediates/super.build/Debug-iphonesimulator/super.build/Objects-normal/x86_64/super_dependency_info.dat -o /Users/teeboy/Library/Developer/Xcode/DerivedData/super-aybvkjtipygrszeyqsnbmtglaaqi/Build/Products/Debug-iphonesimulator/super.app/super

Undefined symbols for architecture x86_64: "_OBJC_CLASS_$__TtC5utils3zip", referenced from: objc-class-ref in libDashboard.a(ASLandingPageVC.o) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

迅速库的名称是“utils的”。遗留目标c应用程序使用其他一些项目依赖项。对不起,新手到Xcode。

不知道你是如何引用Objective-C应用程序中的Swift框架的,我只能猜测你引用了一个框架二进制文件,这个二进制文件是与你试图构建应用程序的平台不同的。

例如,如果您为设备构建了框架,然后将其包含在应用程序构建设置下的框架搜索路径中,则包含生成的.framework目录的目录路径,然后尝试构建应用程序模拟器。如果你使用了正确的框架二进制文件(在这种情况下为模拟器构建的),它将会工作。

但是,更好的方法是在应用程序中嵌入Swift框架。假设框架和应用程序在不同的项目中,您可以执行以下操作:

  • 确保框架项目未在Xcode中打开。
  • 在Xcode中打开应用程序项目。
  • 将框架的.xcodeproj从Finder拖放到Xcode中的应用程序项目中以创建引用。
  • 在General - > Embedded Binaries下添加你的Swift .framework。
  • 当您构建应用程序时,Xcode将构建正确架构的框架并使用并嵌入到您的应用程序中。

有关嵌入框架的更多信息,请参阅https://developer.apple.com/library/content/technotes/tn2435/_index.html。顺便说一句,当链接器失败时,你是否还看到ld关于缺少所需架构的文件的警告?

+0

优秀的omniProg。你的步骤解决了这个问题。从工作区中删除了“swift framework”项目。将它从finder拖放到xcode“App”项目中,现在就可以运行。我必须做的另一个步骤是在应用程序项目属性的“常规”选项卡中将“始终嵌入swift标准库”设置为“yes”。在Visual Studio上工作超过12年后,xCode肯定是不同的野兽!atleast我们有更快更接近C#而不是更客观的C .. – teeboy