将Swift Static库与Objective-C项目一起使用时会出错 [英] It gives errors when using Swift Static library with Objective-C project
问题描述
我需要根据需要创建快速的静态库.我制作了使用swift和Obj-c代码的swift静态库.我已经通过网桥文件包含了Obj-c文件.我能够编译swift静态库而没有任何错误,并获取libMySwift.a文件.我在Swift4中使用Xcode9.3来编译库.
I need to make swift static library for my requirement. I made swift static library which uses swift and Obj-c code. I have included Obj-c files via bridge file. I am able to compile swift static library without any error and get libMySwift.a file. I use Xcode9.3 with Swift4 to compile library.
我在obj-c项目中包含libMySwift.a,并且还包含obj-c兼容标头以访问我的lib在项目中.当我尝试编译项目时,它给出以下警告和200多个错误.
I include libMySwift.a in obj-c project and also included obj-c compatible header to access my lib in the project. When I try to compile the project it give below warning and more than 200 errors.
Auto-Linking library not found for -lswiftSwiftOnoneSupport
Auto-Linking library not found for -lswiftCore
Auto-Linking library not found for -lswiftQuartzCore
Auto-Linking library not found for -lswiftCoreImage
Auto-Linking library not found for -lswiftCoreGraphics
Auto-Linking library not found for -lswiftObjectiveC
Auto-Linking library not found for -lswiftDispatch
Auto-Linking library not found for -lswiftMetal
Auto-Linking library not found for -lswiftFoundation
Auto-Linking library not found for -lswiftUIKit
Auto-Linking library not found for -lswiftDarwin
Auto-Linking library not found for -lswiftCoreFoundation
如果我错过任何步骤或需要添加任何内容,请告诉我.
Please let me know if I am missing any steps or need to add anything.
推荐答案
在我的pod中添加了第一个Swift文件编译为静态库时,我在演示项目中遇到了相同的错误.对我来说,解决方案很简单-只需将空的Swift文件添加到我的演示项目中,该项目以前仅在Objective-C中.这样就解决了所有链接器错误.
I've got the same error on my demo project when added first Swift file in my pod compiled as static library. For me solution was simple - just added empty Swift file to my demo project which was previously in Objective-C only. This solved all linker errors.
这篇关于将Swift Static库与Objective-C项目一起使用时会出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!