63

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.

JonasVautherin
  • 7,297
  • 6
  • 49
  • 95
SBel
  • 3,315
  • 6
  • 29
  • 47

15 Answers15

32

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.

Aniruddha Shevle
  • 4,602
  • 4
  • 22
  • 36
  • 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 " ?? – rohitwtbs Jun 01 '20 at 20:00
  • 1
    @rohitwtbs: https://guides.cocoapods.org/using/faq.html#cocoapods-uses-workspaces-which-are-considered-user-data-why-does-it-not-use-normal-sub-projects – Aniruddha Shevle Jun 02 '20 at 13:49
31

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

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • 31
    you didn't tell how to do it. Show, don't tell. – C.J. Jul 17 '15 at 21:06
  • 7
    In the build settings? Do I need to post an image to make the answer valid? – trojanfoe Jul 17 '15 at 21:25
  • 14
    @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**. – Daniel Aug 28 '19 at 20:41
  • 1
    @Daniel 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. – trojanfoe Aug 29 '19 at 05:58
  • 2
    @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. – user2465201 Sep 10 '21 at 19:34
  • Build Settings -> Search Paths -> Library Search Paths (both Debug and Release) – juan_marti Oct 07 '21 at 10:50
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.

Gon
  • 1,135
  • 12
  • 22
  • 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! – Ajay Parambath Jun 19 '23 at 09:37
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

Scott Jungwirth
  • 6,105
  • 3
  • 38
  • 35
8

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

vr_driver
  • 1,867
  • 28
  • 39
6

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.

Rinni
  • 121
  • 1
  • 3
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
Vikas Shukla
  • 104
  • 3
  • Thanks a lot! This one should be the right answer! – Timur Mustafaev Sep 16 '22 at 21:19
  • 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? – blackkara Oct 07 '22 at 23:25
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

Jacksonkr
  • 31,583
  • 39
  • 180
  • 284
James Martin
  • 1,050
  • 7
  • 8
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

David
  • 11
  • 1
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

  • 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](/help/how-to-answer). – Community Sep 25 '21 at 16:20
0

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

Loegic
  • 3,390
  • 20
  • 33
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.

konsti
  • 629
  • 5
  • 8
0

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

Rikesh Subedi
  • 1,755
  • 22
  • 21
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.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
0

Open your .xcworkspace in Xcode and Make this settings.

enter image description here