It gives errors when using Swift Static library with Objective-C project

22,531

Solution 1

An update to Alex's answer:

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

Solution 2

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.

Share:
22,531
Vishal Gabani
Author by

Vishal Gabani

iOS Developer with 11+ yrs of experience in iOS applications and sdk development

Updated on February 16, 2021

Comments

  • Vishal Gabani
    Vishal Gabani over 3 years

    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.

    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.

  • Antony Raphel
    Antony Raphel over 5 years
    by creating Objective-C bridging Header is resolved the issue.
  • fct
    fct over 5 years
    Sweet. Kind of elegant solution. Xcode shows as warnings not errors. This solution fixed warnings and all erros caused by warnings.
  • jdnichollsc
    jdnichollsc almost 5 years
    but the issue still present if you remove that swift file later :/
  • Naveen Raju
    Naveen Raju over 4 years
    Thank you so much, it solved my issue. By the way, I'm trying to build using react-native.
  • romin21
    romin21 over 4 years
    I've been spending two days trying to fix this issue and you saved me!
  • Tuan Nguyen
    Tuan Nguyen over 4 years
    why i cant see Confirm Create Bridging Header dialog?
  • Kamil Lewandowski
    Kamil Lewandowski about 4 years
    @TuanNguyen just create an empty header file by yourself. In the same directory and targets as your empty swift file. It worked for me.
  • Curtis
    Curtis about 4 years
    I did this and still get the same error. Trying to ad adMob. Could not find auto-linked framework 'FBLPromises'
  • lambinator
    lambinator almost 4 years
    I had to perform this again when upgrading from xcode 11 to 12.
  • papacostas
    papacostas about 3 years
    if a bridging header dialog doesn't prompt, follow this. (to remove old one) stackoverflow.com/questions/31716413/…
  • Dan
    Dan almost 3 years
    For me, with an ejected Expo/react-native project, I simply added the empty swift file and it worked. No bridge dialog needed. Thanks for this!