Why linker link static libraries with errors? iOS

2020-01-24 12:55发布

I have a problem with linking my mixed language framework to a project.

1) I create framework with Swift and Objective-C classes.

2) Main logic was stored in Swift file. For example the class with method that calls NSLog("Swift log was called").

3) Objective-C file has class that has method in which I create an instance of Swift class and call Swift-log method.

4) I link this framework with my Objective-C project, I can call all what 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)"

And warnings:

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 'swiftCoreFoundation'

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 'swiftObjectiveC'

ld: warning: Could not find auto-linked library 'swiftDispatch'

ld: warning: Could not find auto-linked library 'swiftSwiftOnoneSupport'

I also saw the solution with importing empty Swift-file, but it necessary to make project without any trash.

9条回答
We Are One
2楼-- · 2020-01-24 12:57

For XCode 11 beta 4 Library Search Paths should be:

$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)
查看更多
老娘就宠你
3楼-- · 2020-01-24 13:04

In case you encounter this error while using Xcode 11 beta 4 in combination with carthage see this workaround:

https://github.com/Carthage/Carthage/issues/2825

Basically it consists of creating a xcconfig with the fixes and inject these into each build.

查看更多
Animai°情兽
4楼-- · 2020-01-24 13:07

In my case it was a React-Native project after adding a Swift Pods library. Maybe just the step 2 can work:

  1. Adding a new Swift file and a Brigde header:

1) File -> New -> File <code>File -> New -> File</code>

2) Select Swift File Select <code>Swift File</code>

3) Confirm Create Bridging Header enter image description here

  1. Go to Build Settings and set Always Embed Swift Standard Libraries to YES Always Embed Swift Standard Libraries
查看更多
Bombasti
5楼-- · 2020-01-24 13:10

Try this workaround https://stackoverflow.com/a/50495316/1658268

Basically just add a dummy swift file in your project, and re-run your build.

查看更多
劳资没心,怎么记你
6楼-- · 2020-01-24 13:10

I've got the same errors when accidentally compiling a project with a Swift 5.0 Snapshot configured in the Xcode preferences » Components » Toolchain.

查看更多
可以哭但决不认输i
7楼-- · 2020-01-24 13:10

If your Xcode version is >=12.2

Go to

BuildSettings -> Linking -> runpath search path and add

/usr/lib/swift

as your 1st argument like this enter image description here

查看更多
登录 后发表回答