为什么链接器链接有错误的静态库?IOS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52536380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why linker link static libraries with errors? iOS
提问by Yaroslav Skachkov
I have a problem with linking my mixed language framework to a project.
我在将混合语言框架链接到项目时遇到问题。
1) I create a framework with Swift and Objective-C classes.
1) 我用 Swift 和 Objective-C 类创建了一个框架。
2) The main logic was stored in the Swift file. For example the class with a method that calls NSLog("Swift log was called").
2) 主要逻辑存储在 Swift 文件中。例如具有调用 NSLog("Swift log was called") 方法的类。
3) Objective-C file has a class that has a method in which I create an instance of Swift class and call Swift-log method.
3)Objective-C 文件有一个类,该类有一个方法,我在其中创建 Swift 类的实例并调用 Swift-log 方法。
4) I link this framework with my Objective-C project, I can call all that I need in this project, but when I want to build this project I receive error "linker command failed with exit code 1 (use -v to see invocation)
"
4) 我将这个框架与我的 Objective-C 项目联系起来,我可以在这个项目中调用我需要的所有东西,但是当我想构建这个项目时,我收到错误“ linker command failed with exit code 1 (use -v to see invocation)
”
And warnings:
和警告:
ld: warning: Could not find auto-linked library 'swiftFoundation'
ld: warning: Could not find auto-linked library 'swiftFoundation'
ld: warning: Could not find auto-linked library 'swiftDarwin'
ld: warning: Could not find auto-linked library 'swiftDarwin'
ld: warning: Could not find auto-linked library 'swiftCoreFoundation'
ld: warning: Could not find auto-linked library 'swiftCoreFoundation'
ld: warning: Could not find auto-linked library 'swiftCore'
ld: warning: Could not find auto-linked library 'swiftCore'
ld: warning: Could not find auto-linked library 'swiftCoreGraphics'
ld: warning: Could not find auto-linked library 'swiftCoreGraphics'
ld: warning: Could not find auto-linked library 'swiftObjectiveC'
ld: warning: Could not find auto-linked library 'swiftObjectiveC'
ld: warning: Could not find auto-linked library 'swiftDispatch'
ld: warning: Could not find auto-linked library 'swiftDispatch'
ld: warning: Could not find auto-linked library 'swiftSwiftOnoneSupport'
ld: warning: Could not find auto-linked library 'swiftSwiftOnoneSupport'
I also saw the solution with importing empty Swift-file, but it necessary to make a project without any trash.
我也看到了导入空 Swift 文件的解决方案,但有必要制作一个没有任何垃圾的项目。
回答by Hussam Kurd
- Open ios/YourAppName.xcodeproj in Xcode
- Right-click on Your App Name in the Project Navigator on the left, and click New File…
- Create a single empty Swift file to the project (make sure that Your App Name target is selected when adding)
- when Xcode asks, press Create Bridging Header and do not remove Swift file then. re-run your build.
- 在 Xcode 中打开 ios/YourAppName.xcodeproj
- 在左侧的项目导航器中右键单击您的应用程序名称,然后单击新建文件...
- 为项目创建一个空的 Swift 文件(确保在添加时选择了 Your App Name 目标)
- 当 Xcode 询问时,按 Create Bridging Header,然后不要删除 Swift 文件。重新运行你的构建。
This should fix the problem
这应该可以解决问题
回答by Nathan
Apparently for pure objective-c projects you will need to add this $(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)
to the library search pathsof your target. This worked for me when I was including a library written in swift to a project in objective-c
显然,对于纯objective-c 项目,您需要将其添加$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)
到目标的库搜索路径中。当我将一个以 swift 编写的库包含在 Objective-c 的项目中时,这对我有用
回答by AlVelig
回答by Aleksey Gotyanov
For XCode 11 beta 4 Library Search Pathsshould be:
对于 XCode 11 beta 4库搜索路径应该是:
$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)
回答by SudoPlz
Try this workaround https://stackoverflow.com/a/50495316/1658268
试试这个解决方法https://stackoverflow.com/a/50495316/1658268
Basically just add a dummy swift file in your project, and re-run your build.
基本上只需在您的项目中添加一个虚拟的 swift 文件,然后重新运行您的构建。
回答by Ralf Ebert
I've got the same errors when accidentally compiling a project with a Swift 5.0 Snapshot configured in the Xcode preferences ? Components ? Toolchain.
使用 Xcode 首选项中配置的 Swift 5.0 快照意外编译项目时,我遇到了相同的错误?成分 ?工具链。
回答by Jimmy Sorza
if you come from lottie-react-native install instructionsjust add use_frameworks!
to podFile #536 (comment)
如果您来自lottie-react-native 安装说明,只需添加use_frameworks!
到 podFile #536(评论)
回答by hakiko
https://stackoverflow.com/a/56187043/1848929works like a charm.
https://stackoverflow.com/a/56187043/1848929就像一个魅力。
Just create empty swift file on your project then build your project. Thats it.
只需在您的项目上创建空的 swift 文件,然后构建您的项目。就是这样。
回答by leolmq
@AlVelig 's answer worked for me.
@AlVelig 的回答对我有用。
My case is a Flutter Project, and I add a package (searchable_dropdown), which is write by Swift.
我的案例是一个 Flutter 项目,我添加了一个包(searchable_dropdown),它是由 Swift 编写的。
The output warning is:
输出警告是:
Could not find auto-linked library 'swiftObjectiveC'
找不到自动链接库“swiftObjectiveC”
Could not find auto-linked library 'swiftCore'
找不到自动链接的库“swiftCore”
......
......
回答by Amir Ardalan
I only forget to Add the new Framework to my pod file :)
我只是忘记将新框架添加到我的 pod 文件中:)
target 'Data' do
inherit! :search_paths
pod 'AlamofireObjectMapper', '~> 5.2'
end
结尾