68

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.

  • 4
    I found this that solved my problem: stackoverflow.com/a/50495316/2842800 – phips28 Sep 28 '18 at 14:28
  • @PhilippHolly I need a solution that will not include empty files. – Yaroslav Skachkov Oct 1 '18 at 7:22
  • I am sorry, I have not found any solution so far. let me know if you find something. – phips28 Oct 2 '18 at 18:10

16 Answers 16

125
  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

| improve this answer | |
  • 7
    Yes, use this if you have the problem with Swift 5 / Xcode 10.2 / Mac OS 10.14.4 / iOS 12.2.2 – Mark Sergienko Apr 19 '19 at 8:26
  • 2
    Incroyable... I don't even know what this REALLY did, but I tried it and it fixed my issue. Swift 5 / Xcode 10.2 / Mac OS 10.14.6 – Will Sep 10 '19 at 18:34
  • This worked for me. MacOS Catalina 10.15.2 XCode 11.3.1 RN 0.61.5 – Yeshan Jay Jan 28 at 9:42
  • 1
    Works like a charm. Can someone explain why tho? – RadioLog Feb 13 at 11:38
  • What If I already have an existing bridging header and the problem persists? I'm running on MacOS Mojave and XCode 11.3.1 – blastervla Mar 2 at 13:45
83

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

| improve this answer | |
  • 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 – Amr Angry Jan 7 '19 at 22:07
  • 8
    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. – LarryFisherman Mar 6 '19 at 0:54
  • 6
    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. – megastep Mar 30 '19 at 2:04
  • 2
    For those who are new to Xcode make sure "All" is selected and is blue else you might not find Library search path – amar Aug 12 '19 at 4:54
  • 1
    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) – Fantasim Sep 18 '19 at 12:00
70

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
| improve this answer | |
  • Where will i put the file, under pods or the project? – lutakyn Aug 20 '19 at 18:37
  • @lutakyn I've put it in the project – AlVelig Aug 21 '19 at 20:55
  • 2
    This worked for me for my react native build => RN 60.5, updated cocoapods to 1.8.4, then did this and it fixed my build issues (did a build folder clean as well). – IronWorkshop Oct 27 '19 at 7:28
  • 1
    Worked for me without the last step >Go to Build Settings and set Always Embed Swift Standard Libraries to YES – Oleg Dater Dec 4 '19 at 7:24
  • 1
    @dcangulo that steps appears only if your filename contains "bridging-header" – Luca Davanzo Mar 13 at 9:04
19

For XCode 11 beta 4 Library Search Paths should be:

$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)
| improve this answer | |
  • 1
    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. – Tap Forms Jul 24 '19 at 18:04
  • Any targets with Swift code need to have the above mentioned path for XCode 11 – gom1 Sep 17 '19 at 22:23
11

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

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

| improve this answer | |
  • 2
    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. – Yaroslav Skachkov Oct 24 '18 at 8:46
7
  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
| improve this answer | |
  • you saved my life !!! – Hoang Lam 2 days ago
2

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

| improve this answer | |
  • I've changed it on purpose...any way I can compile it on arm64 (works fine on simulator)? – Kirow May 3 '19 at 14:39
2

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
| improve this answer | |
1

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

| improve this answer | |
0

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.

| improve this answer | |
0

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

| improve this answer | |
  • 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" – Cristiano Santos Jul 16 at 9:45
0

https://stackoverflow.com/a/56187043/1848929 works like a charm.

Just create empty swift file on your project then build your project. Thats it.

| improve this answer | |
  • 1
    After selecting Swift File and then clicking Next does not show Create Bridging Header but instead Save As: then Create. Any ideas? – dcangulo Mar 11 at 7:22
0

@AlVelig 's answer worked for me.

My case is a Flutter Project, and I add a package (searchable_dropdown), which is write by Swift.

The output warning is:

Could not find auto-linked library 'swiftObjectiveC'

Could not find auto-linked library 'swiftCore'

......

| improve this answer | |
0

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

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

end

| improve this answer | |
0

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.

| improve this answer | |
0

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 :)

| improve this answer | |
New contributor
SerhiiVolynets is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • 1
    @SehiiVolynets, Please use italics (use * brackets) for pathways. – maciejwww 2 hours ago

Your Answer

By clicking ā€œPost Your Answerā€, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.