xcode library not found
Asked Answered
F

15

66

I'm getting the following error:

ld: library not found for -lGoogleAnalytics clang: error: linker command failed with exit code 1 (use -v to see invokation)

I've spent some time googling but can't find how to fix this problem. I'm new to xcode and this is an existing project that I need to work on.

Federica answered 6/7, 2012 at 8:28 Comment(1)
I'm getting the same error whenever i try to archive .ipa. How did you solve it ?Ours
T
34

In my case, the project uses CocoaPods. And some files are missing from my project.

So I install it from CocoaPods: https://cocoapods.org/.

And if the project uses CocoaPods we've to be aware to always open the .xcworkspace folder instead of the .xcodeproj folder in the Xcode.

Tamikatamiko answered 5/12, 2019 at 3:51 Comment(2)
what is the reason "if the project uses CocoaPods we've to be aware to always open the .xcworkspace folder instead of the .xcodeproj " ??Rb
@rohitwtbs: guides.cocoapods.org/using/…Tamikatamiko
H
32

You need to set the "linker search paths" of the project (for both Debug and Release builds). If this library was in, say, a sibling directory to the project then you can set it like this:

$(PROJECT_DIR)/../GoogleAnalytics/lib

(you want to avoid using an absolute path, instead keep the library directory relative to the project).

Housel answered 6/7, 2012 at 8:49 Comment(6)
you didn't tell how to do it. Show, don't tell.Changteh
In the build settings? Do I need to post an image to make the answer valid?Housel
@trojanfoe, yes as this would have helped others who may not have as much experience in Xcode as you. For example, I am familiar with Header Search Paths, but I have no idea where the "linker search path" is in Build Settings.Virgievirgil
@Virgievirgil The Linker Search Path is the -L option to the linker (ld). It's not so much about experience with Xcode as experience with the underlying tools; Xcode provides simplified access to the options of the compiler/linker/etc. however it's assumed you know what the options do.Housel
@Daniel, this is the challenge with XCode: If I'm content building things using command line scripts, I can add any options I'd like. With XCode, knowing the option you want is not the same as knowing how to get XCode to add it. So IMO it is indeed experience with XCode that is at issue. Even when you add an option where you're supposed to (like Library Search Paths), it still often doesn't work, and debugging what's wrong is incredibly difficult.Jadwiga
Build Settings -> Search Paths -> Library Search Paths (both Debug and Release)Broyles
G
20

All in all, the Xcode cannot find the position of library/header/framework, then you tell Xcode where they are.

set the path that Xcode use to find library/header/framework in Build Settings --> Library/Header/Framework Search Paths.

Say, now it cannot find -lGoogleAnalytics, so you add the directory where -lGoogleAnalytics is to the Library Search Paths.

Gaynor answered 29/9, 2013 at 5:19 Comment(1)
Thanks for the suggestion, but my error is different. I'm getting the 'Library not found for -lPods' error. I've checked Library Search Paths in Build Settings, and the path seems correct. Any suggestions to resolve this specific error? Thanks!Logomachy
L
14

In my case I had a project with lots of entries in "Build Settings > Other Linker Flags"

I needed to reduce it down to just

  $(inherited)
  -ObjC

Old settings:

old settings

Updated settings:

enter image description here

Luminiferous answered 3/3, 2017 at 22:5 Comment(0)
P
8

For me, I open the projectname.xcworkspace file and it all works.

Perfecto answered 15/12, 2019 at 5:33 Comment(0)
H
5

If you have pods installed, make sure to open the workspace folder (white Xcode icon) not the project folder. This resolved the library not found for ... error. Very simple issue but I was stuck on this for a long time.

Hayden answered 8/10, 2019 at 0:40 Comment(0)
N
4

This worked for me:

  1. Go to build setting -> Linking -> Other Linker Flags -> Remove all other than $(inherited)
  2. Cd ios && pod updateenter image description here
Nuthatch answered 23/8, 2021 at 7:43 Comment(2)
Thanks a lot! This one should be the right answer!Tartrate
I was in the loop of 'clean something, clean something too, then pod install, delete pods folder, delete podfile.lock" from many accepted answers or questions. I can't believe this is worked for me! Please explain what this linker is. Why do I need to delete its contents? And In what periods should we repeat this process again? Until this appears again?Counterpoison
M
2

If you are using Pods to include the GoogleAnalytics iOS SDK into your project, it's worth noting that since the 3.0 release your Other Linker Flags needs to include -lGoogleAnalyticsServices not the old -lGoogleAnalytics

Masuria answered 7/11, 2013 at 11:6 Comment(0)
K
1

If your library file is called libGoogleAnalytics.a you need to put -lGoogleAnalytics so make sure the .a file is named as you'd expect

Kitts answered 29/5, 2013 at 5:52 Comment(0)
C
1

None of the above worked for me, what did was making sure the Pod file platform :ios, '11.0' matched with the minimum deployment target in the XCODE setting

Contaminant answered 25/9, 2021 at 13:44 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Diesel
B
1

Open your .xcworkspace in Xcode and Make this settings.

enter image description here

Backbreaker answered 25/7, 2023 at 16:10 Comment(0)
R
0

You can also try to lint with the --use-library option, as cocoapods lint libraries as framework by default since v0.36

Retrogradation answered 2/9, 2015 at 16:32 Comment(0)
B
0

The problem might be the following: SVN ignores .a files because of its global config, which means someone didn't commit the libGoogleAnalytics.a to SVN, because it didn't show up in SVN. So now you try to check out the project from SVN which now misses the libGoogleAnalytics.a (since it was ignored and was not committed). Of course the build fails.

You might want to change the global ignore config from SVN to stop ignoring *.a files.

Or just add the one missing libGoogleAnalytics.a file manually to your SVN working copy instead of changing SVNs global ignore config.

Then re-add libGoogleAnalytics.a to your XCode project and commit it to SVN.

Batish answered 13/10, 2016 at 11:51 Comment(0)
C
0

In XCode 10.1, I had to set "Library Search Paths" to something like $(PROJECT_DIR)/.../path/to/your/library

Chorion answered 25/2, 2019 at 2:12 Comment(1)
How can I find the path to the library?Counterspy
E
0

For me it was a silly thing: my mac uploaded the file into iCloud, and that is why Xcode did not find it.

If you turn off the automatic upload, it wont happen again.

Eminence answered 24/7, 2020 at 15:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.