Why do I get iOS linker errors with my static libraries?

94,799

Solution 1

  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

Solution 2

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 3

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

Solution 4

For XCode 11 beta 4 Library Search Paths should be:

$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)

Solution 5

I have export my unity project. Earlier it was working just to add empty swift file with press create Bridging Header.

but recently i have updated my xCode to 12.3 and it stop working.

So, tried few other ways.

I have added $(SDKROOT)/usr/lib/swift to Build settings > Search paths > Library search paths.

but still it doesn't work. So, i have added in same path i.e Build settings > Search paths > Library search paths.

$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)

$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)

Now it working perfect. Didn't get exact problem or solution but it works well with this way.

I just add these three in Build settings > Search paths > Library search paths.

  1. $(SDKROOT)/usr/lib/swift
  2. $(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)
  3. $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)

Separately TOOLCHAIN_DIR directories doesn't work. If i add $(SDKROOT)/usr/lib/swift then only it work.

Share:
94,799

Related videos on Youtube

Yaroslav Skachkov
Author by

Yaroslav Skachkov

Updated on April 13, 2022

Comments

  • Yaroslav Skachkov
    Yaroslav Skachkov about 2 years

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

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

    2. The main logic was stored in the Swift file. For example the class with a method that calls 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.

    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)

      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 a project without any trash.

    • Yaroslav Skachkov
      Yaroslav Skachkov over 5 years
      @PhilippHolly I need a solution that will not include empty files.
    • phips28
      phips28 over 5 years
      I am sorry, I have not found any solution so far. let me know if you find something.
    • Akila Devinda
      Akila Devinda over 2 years
      Hi Any solution for this ?
  • Yaroslav Skachkov
    Yaroslav Skachkov over 5 years
    You are the second who suggest this solution :). As I said in comments to description of my question, I need solution without empty Swift-files.
  • Amr Angry
    Amr Angry over 5 years
    can you give us an example how we can added, as i am trying it but i don't really work for me , maybe aim placing it in a wrong place
  • huangxinyu
    huangxinyu about 5 years
    @Nathan How to set this in podspec, and not need add it manually?
  • LarryFisherman
    LarryFisherman about 5 years
    This worked perfectly! For anyone wondering how exactly to do this; click your xcode project in the file explorer -> under Targets select your target -> select the Build Settings tab -> search for Library Search Paths and add $(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME) to the debug and release sections.
  • megastep
    megastep about 5 years
    Unfortunately this trick seems to have stopped working when using Swift 5 with Xcode 10.2 - probably because there are now system-wide Swift libs with iOS 12.2.
  • Kirow
    Kirow about 5 years
    I've changed it on purpose...any way I can compile it on arm64 (works fine on simulator)?
  • Tap Forms
    Tap Forms almost 5 years
    I had to add this to each of my targets Library Search Paths property. Not just the main app. So, including my watch kit and Siri Intents targets.
  • amar
    amar almost 5 years
    For those who are new to Xcode make sure "All" is selected and is blue else you might not find Library search path
  • lutakyn
    lutakyn almost 5 years
    Where will i put the file, under pods or the project?
  • AlVelig
    AlVelig almost 5 years
    @lutakyn I've put it in the project
  • Almas Adilbek
    Almas Adilbek over 4 years
    @megastep so how do fix it?
  • gom1
    gom1 over 4 years
    Any targets with Swift code need to have the above mentioned path for XCode 11
  • gom1
    gom1 over 4 years
    Try adding the following to your target's library search path: $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)
  • Fantasim
    Fantasim over 4 years
    It compiles but then I got a crash at the launch of the application: "This copy of libswiftCore.dylib requires an OS version prior to 12.2.0". If you want to solve it just add an empty swift file in the project, keep it forever and it will work. (The problem come from the fact that you are using both objective-c and swift code in your app)
  • Nader Ghanbari
    Nader Ghanbari over 4 years
    Do not remove the dummy Swift file after the bridging file is created! Keep it or build fails
  • blastervla
    blastervla about 4 years
    What If I already have an existing bridging header and the problem persists? I'm running on MacOS Mojave and XCode 11.3.1
  • dcangulo
    dcangulo about 4 years
    Step Create Bridging Header does not appear for me. It says Save File for me.
  • Luca Davanzo
    Luca Davanzo about 4 years
    @dcangulo that steps appears only if your filename contains "bridging-header"
  • Cristiano Santos
    Cristiano Santos almost 4 years
    Can someone explain to me why the -1? Because I tried this and now I no longer need to constantly Clean => Rebuild whenever I change a single line. Note: I also needed to set "Enable Bitcode" as "No"
  • maciejwww
    maciejwww over 3 years
    @SehiiVolynets, Please use italics (use * brackets) for pathways.
  • bona912
    bona912 over 3 years
    what if you're already have bridging file, can someone explain please
  • scaly
    scaly over 3 years
    Note if you have this in Xcode 12 still, it can f* your build.]\
  • easytarget
    easytarget over 3 years
    @maciejwww, what do you mean by "italics" and "asterisk brackets"? Which one should be used?
  • maciejwww
    maciejwww over 3 years
    I mean formatting policy on StackOverflow. Using asterisk brackets formats text into italics: *text* --> text. For pathways in GUI, it's recommended to use italics or bold (double asteriks: **text**) font. However, in this case is better to use bold font than italics, I suppose. Now, my comment is no longer needed because @Niko have edited yours answer. Check it out and compare with your version. Short info about text fotmatting and example you can find here.
  • Robert Bentley
    Robert Bentley about 3 years
    Worked for me! Thanks Xcode 12.5 iOS 14.5
  • xhg
    xhg about 3 years
    Tested in Xcode 12.5, $(SDKROOT)/usr/lib/swift needs to be the first
  • John Stuart
    John Stuart almost 3 years
    Xcode does not ask 'Create Bridging Header' , Xcode version: 12.4
  • Pauli Kettunen
    Pauli Kettunen almost 3 years
    Hey thanks a lot for this! Changing the Library Search Paths from swift-5.0 to swift-5.2 made my app finally build and run (it has nothing to do with watch apps or widgets).
  • Engr.Aftab Ufaq
    Engr.Aftab Ufaq over 2 years
    what lottie-react-native version you install
  • KentAgent
    KentAgent over 2 years
    Hello @AftabAmin , thanks for the downvote 😏. If you read my post you'll see I follow the documentation over at the lottie RN docs: github.com/lottie-react-native/lottie-react-native At the time of posting this a year ago I'm not too sure the version but give it a go with the latest stable release. Good luck!
  • Engr.Aftab Ufaq
    Engr.Aftab Ufaq over 2 years
    I have tried all the updated version but non is working. when I remove these libraries it works fine. tow months later my app was running. today I was updating my app and suddenly got this issue. also faced this a month ago but then I solved it.
  • KentAgent
    KentAgent over 2 years
    @AftabAmin I see, that's too bad. let the devs over at lottie RN know about this by opening a through issue perhaps. Might help more people than yourself. Too bad I can't be of anymore help. Been a while since I worked with lottie.
  • Patrick DaVader
    Patrick DaVader over 2 years
    Worked fine for me, thanks a lot!!
  • Anonimys
    Anonimys over 2 years
    Thanks, it work for Xcode 13.1
  • moralejaSinCuentoNiProverbio
    moralejaSinCuentoNiProverbio about 2 years
    Thanks, it work for Xcode 13.2
  • Jamal Ud Din
    Jamal Ud Din about 2 years
    @AftabAmin, how you fix it??