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条回答
Emotional °昔
2楼-- · 2020-01-24 13:11

Apparently for pure objective-c projects you will need to add this $(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME) to the library search paths of your target. This worked for me when I was including a library written in swift to a project in objective-c

查看更多
Fickle 薄情
3楼-- · 2020-01-24 13:17
  1. Open ios/YourAppName.xcodeproj in Xcode
  2. Right-click on Your App Name in the Project Navigator on the left, and click New File…
  3. Create a single empty Swift file to the project (make sure that Your App Name target is selected when adding)
  4. when Xcode asks, press Create Bridging Header and do not remove Swift file then. re-run your build.

This should fix the problem

查看更多
甜甜的少女心
4楼-- · 2020-01-24 13:17

XCode 11.3 beta, Swift 5.0

I just add my targets to the podfile:

platform :ios, '9.0' 
use_frameworks! 
inhibit_all_warnings!

def shared_pods
    # Pods for NamaIOS
    pod 'Alamofire'
    pod 'RxSwift'
end

target 'MyApp' do
  use_frameworks!

  shared_pods

end

target 'MyApp-Test' do
  use_frameworks!

  shared_pods

end

target 'MyApp-Development' do
  use_frameworks!

  shared_pods

end
查看更多
登录 后发表回答