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

IosObjective CSwiftStatic LibrariesStatic Linking

Ios Problem Overview


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.

Ios Solutions


Solution 1 - Ios

  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 - Ios

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 File -> New -> File

  2. Select Swift File Select Swift File

  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 - Ios

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 - Ios

For XCode 11 beta 4 Library Search Paths should be:

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

Solution 5 - Ios

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.

Solution 6 - Ios

  1. Right click project name and add a new swift file leave it as File.swift
  2. it will ask you to create a new bridging header accept
  3. Run the project again

Solution 7 - Ios

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

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

Solution 8 - Ios

If you have issue after update xCode to version 12 and errors

> Could not find or use auto-linked library 'swiftWebKit'

and two more.

Just addd $(SDKROOT)/usr/lib/swift to the Build settings > Search paths > Library search paths.

Hope its help :)

Solution 9 - Ios

Xcode 12.5, React Native.

Change: 'Library Search Paths' from Swift-5.0 to Swift-5.2enter image description here

Solution 10 - Ios

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

Solution 11 - Ios

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

Solution 12 - Ios

What worked for me in a React Native project is to move $(inherited) to the bottom of the list in Build Settings -> Library Search Paths

enter image description here

Solution 13 - Ios

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

Solution 14 - Ios

if you come from lottie-react-native install instructions just add use_frameworks! to podFile #536 (comment)

Solution 15 - Ios

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.

Solution 16 - Ios

I only forget to Add the new Framework to my pod file :)

 target 'Data' do
inherit! :search_paths
 pod 'AlamofireObjectMapper', '~> 5.2'

end

Solution 17 - Ios

for Xcode 12.2

Create an Empty Swift file using Xcode, such as named Void.swift, and every issue will be solved by Xcode automatically.

Solution 18 - Ios

I ran into this issue with our project and the issue was that there were orphaned references to lottie in our xcode project file. Opening that in a text editor and removing them fixed the issue for me.

Solution 19 - Ios

I am android programmer. It took me a while understand what they were doing. I have currently Xcode 13.2.1 And flutter 1 awful combination I know. Please edit in other side xcode will take the enter like "I end" I change Build settings > Search paths > Library search paths.: From:

> $(inherited) $(PROJECT_DIR)/Flutter

to:

> $(inherited) $(PROJECT_DIR)/Flutter $(SDKROOT)/usr/lib/swift > $(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME) > $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)

Thats all, I hope to help some folk.

Solution 20 - Ios

I am getting this error after installing Lottie-react-native?

The solution only works if it is caused by adding Lottie package.

This worked for me:

yarn add lottie-react-native
yarn add lottie-ios@3.2.3

And then must run:

pod install or pod update

I am using:

"lottie-ios": "3.2.3",
"lottie-react-native": "^5.0.1",
"react": "17.0.2",
"react-native": "0.67.3"

Solution 21 - Ios

What solved it for me when trying to integrate Lottie in my React Native project was to uninstall the lottie-ios and lottie-react-native modules with npm.

npm uninstall lottie-react-native lottie-ios

Make sure the files are unlinked as well

npx react-native unlink lottie-react-native lottie-ios

I also had the bridging-file in my project from previously trying that method without success so in order to replicate my process, follow the suggested answer and add that file to your project as well.

After these steps, I went ahead and deleted my Pods folder, cleaned my build from xcproject and xcworkspace (maybe one of these is enough). After that I went ahead and installed the modules again

npm i --save lottie-react-native lottie-ios@3.1.3

(Make sure to check the current docks over at the lottie repo for the up-to-date versions.)

After you have reinstalled the modules, cd into your ios folder and run pod install.

Open up your xcworkspace in Xcode and run your project (make sure your build is clean).

This solved my issue.

Best of luck.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionYaroslav SkachkovView Question on Stackoverflow
Solution 1 - IosHussam KurdView Answer on Stackoverflow
Solution 2 - IosAlVeligView Answer on Stackoverflow
Solution 3 - IosNathanView Answer on Stackoverflow
Solution 4 - IosAleksey GotyanovView Answer on Stackoverflow
Solution 5 - IosSaveenView Answer on Stackoverflow
Solution 6 - IosChinedu OforView Answer on Stackoverflow
Solution 7 - IosSudoPlzView Answer on Stackoverflow
Solution 8 - IosSerhiiVolynetsView Answer on Stackoverflow
Solution 9 - IosErik DreifaldtView Answer on Stackoverflow
Solution 10 - IosahcodesView Answer on Stackoverflow
Solution 11 - IosRalf EbertView Answer on Stackoverflow
Solution 12 - IosB. MohammadView Answer on Stackoverflow
Solution 13 - IosMohsen KhosraviniaView Answer on Stackoverflow
Solution 14 - IosJimmyWj4EHiMView Answer on Stackoverflow
Solution 15 - IossnodView Answer on Stackoverflow
Solution 16 - IosAmir ArdalanView Answer on Stackoverflow
Solution 17 - IosNrvView Answer on Stackoverflow
Solution 18 - IosTALEView Answer on Stackoverflow
Solution 19 - IosmoralejaSinCuentoNiProverbioView Answer on Stackoverflow
Solution 20 - IosJamal Ud DinView Answer on Stackoverflow
Solution 21 - IosKentAgentView Answer on Stackoverflow