Why do I get iOS linker errors with my static libraries?
Solution 1
- Open ios/YourAppName.xcodeproj in Xcode
- Right-click on Your App Name in the Project Navigator on the left, and click New File…
- Create a single empty Swift file to the project (make sure that Your App Name target is selected when adding)
- 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:
- Adding a new Swift file and a Brigde header:
3) Confirm Create Bridging Header
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.
- $(SDKROOT)/usr/lib/swift
- $(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)
- $(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.
Related videos on Youtube
Yaroslav Skachkov
Updated on April 13, 2022Comments
-
Yaroslav Skachkov about 2 years
I have a problem with linking my mixed language framework to a project.
I create a framework with Swift and Objective-C classes.
The main logic was stored in the Swift file. For example the class with a method that calls NSLog("Swift log was called").
Objective-C file has a class that has a method in which I create an instance of Swift class and call Swift-log method.
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 over 5 years@PhilippHolly I need a solution that will not include empty files.
-
phips28 over 5 yearsI am sorry, I have not found any solution so far. let me know if you find something.
-
Akila Devinda over 2 yearsHi Any solution for this ?
-
Yaroslav Skachkov over 5 yearsYou 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 over 5 yearscan 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 about 5 years@Nathan How to set this in podspec, and not need add it manually?
-
LarryFisherman about 5 yearsThis worked perfectly! For anyone wondering how exactly to do this; click your xcode project in the file explorer -> under
Targets
select your target -> select theBuild Settings
tab -> search forLibrary Search Paths
and add$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)
to the debug and release sections. -
megastep about 5 yearsUnfortunately 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 about 5 yearsI've changed it on purpose...any way I can compile it on arm64 (works fine on simulator)?
-
Tap Forms almost 5 yearsI 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 almost 5 yearsFor those who are new to Xcode make sure "All" is selected and is blue else you might not find Library search path
-
lutakyn almost 5 yearsWhere will i put the file, under pods or the project?
-
AlVelig almost 5 years@lutakyn I've put it in the project
-
Almas Adilbek over 4 years@megastep so how do fix it?
-
gom1 over 4 yearsAny targets with Swift code need to have the above mentioned path for XCode 11
-
gom1 over 4 yearsTry adding the following to your target's library search path: $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)
-
Fantasim over 4 yearsIt 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 over 4 yearsDo not remove the dummy Swift file after the bridging file is created! Keep it or build fails
-
blastervla about 4 yearsWhat If I already have an existing bridging header and the problem persists? I'm running on
MacOS Mojave
andXCode 11.3.1
-
dcangulo about 4 yearsStep
Create Bridging Header
does not appear for me. It saysSave File
for me. -
Luca Davanzo about 4 years@dcangulo that steps appears only if your filename contains "bridging-header"
-
Cristiano Santos almost 4 yearsCan 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 over 3 years@SehiiVolynets, Please use italics (use
*
brackets) for pathways. -
bona912 over 3 yearswhat if you're already have bridging file, can someone explain please
-
scaly over 3 yearsNote if you have this in Xcode 12 still, it can f* your build.]\
-
easytarget over 3 years@maciejwww, what do you mean by "italics" and "asterisk brackets"? Which one should be used?
-
maciejwww over 3 yearsI 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 about 3 yearsWorked for me! Thanks Xcode 12.5 iOS 14.5
-
xhg about 3 yearsTested in Xcode 12.5,
$(SDKROOT)/usr/lib/swift
needs to be the first -
John Stuart almost 3 yearsXcode does not ask 'Create Bridging Header' , Xcode version: 12.4
-
Pauli Kettunen almost 3 yearsHey 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 over 2 yearswhat lottie-react-native version you install
-
KentAgent over 2 yearsHello @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 over 2 yearsI 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 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 over 2 yearsWorked fine for me, thanks a lot!!
-
Anonimys over 2 yearsThanks, it work for Xcode 13.1
-
moralejaSinCuentoNiProverbio about 2 yearsThanks, it work for Xcode 13.2
-
Jamal Ud Din about 2 years@AftabAmin, how you fix it??