57

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
  • 6,362
  • 6
  • 48
  • 77
SBel
  • 3,185
  • 5
  • 26
  • 46

14 Answers14

28

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
  • 118,129
  • 19
  • 204
  • 237
  • 30
    you didn't tell how to do it. Show, don't tell. – C Johnson 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
  • 12
    @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
  • 1
    @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
26

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,156
  • 2
  • 20
  • 34
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,095
  • 12
  • 20
12

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
  • 5,238
  • 2
  • 33
  • 32
6

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

vr_driver
  • 1,547
  • 23
  • 35
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.

Rinni
  • 93
  • 1
  • 2
  • Thanks!! That worked for me. As you said, it's very simple but I didn't realise until I read your answer! – Jaime S Nov 15 '19 at 20:51
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
  • 30,630
  • 38
  • 174
  • 276
James Martin
  • 1,030
  • 7
  • 8
2

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
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
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,270
  • 19
  • 32
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
  • 599
  • 3
  • 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,637
  • 21
  • 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
  • 43,040
  • 110
  • 45
  • 72
0

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