xcode library not found - xcode

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.

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.

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

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.

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:
Updated settings:

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

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.

This worked for me:
Go to build setting -> Linking -> Other Linker Flags -> Remove all other than $(inherited)
Cd ios && pod update

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

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

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

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

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.

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

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.

Related

Compile in Xcode Prefix.pch not found

I am a beginner in react-native. I tried to compile the apps, ran the pod install (because I used cocoapods I have to do this, I guess), and opened the generated xcworkspace. After I hit the compile button, this error show up
Showing All Messages
No such file or directory: '/Users/<username>/Library/Developer/Xcode/DerivedData/<project name>-bvczmgvzvgwjpyfsmvczxliopbfo/Build/Intermediates.noindex/PrecompiledHeaders/SharedPrecompiledHeaders/7446126693023229553/Prefix.pch'
The xcconfig file I used already had GCC_PREFIX_HEADER and targeted on correct file. It stated like this
GCC_PREFIX_HEADER = $(SRCROOT)/ExportedProject/Classes/Prefix.pch;
I checked my project's configurations using target "Release" and it pointed to the correct xcconfig file.
I searched around and found this SO. I checked on my Build Settings > Apple Clang - Language - Prefix Header, and it also targeted on the correct path and has the Precompile Prefix Header filled with "Yes".
I tried to use pod-deintegrate; reimport the project; deleted the project and use react-native upgrade, but nothing works.

GeneratedInfoPlistDotEnv.h file is not found

I have a issue, regarding Xcode, in react-native permission file
in which GeneratedInfoPlistDotEnv.h file is not found.
How to fix this?
Already changed Info.plist Preprocessor Prefix File to
${CONFIGURATION_BUILD_DIR}/GeneratedInfoPlistDotEnv.h
but it did not solve.
issue is:
:1:10: fatal error:
'/Users/DAMAGE/Library/Developer/Xcode/DerivedData/EmployWise-fzbhiywasjfdjnfqjsfnxjbhahzs/Build/Products/GeneratedInfoPlistDotEnv.h'
file not found
Was getting this from react-native-config cocoapod. But its been fixed in v1.4.11. Was due to the older version not writing output script variables, which XCode 14 requires
This issue comes when react native is not able to link to the configuration file like .env file created in your react native environment. If you have used any react native config framework like react-native-config. then make sure this framework is linked for your iOS environment as shown below
react-native link react-native-config
If you are using react-native version >= 0.60 then follow the below steps after linking is done.
Go to ios folder and run pod install.
Next do the following:
1. Remove Derived Data from Xcode
2. Clean Build Folder
3. Build the project again
I had this problem, my solution was to change the Xcode build system from "Legacy Build System" to "New Build System" in the Workspace Settings under the File menu
In my case, I was trying to add a new target for rn-extensions-share and forgot to add all necessary libraries for that new target.

Xcode: ld: library not found for -lAFNetworking

Because of this one reason, build always fails...Any ideas about what I could try?
EDIT: the solution is to open the xcworkspace instead of the xcproject!
Might be you are opening .xcodeproj file after installing pods. Close the project and open .xcworkspace file.
Have the same issue.
What I did with the help of https://premium.wpmudev.org/forums/topic/anybody-solved-this-linker-command-failed-with-exit-code-1 and Adlair Cerecedo-Mendez
Delete the "Pods" project on the left panel of Xcode.
Close Xcode and delete this file in the finder too.
Install pods again.
Open Xcode and clean.
Verify that the build option "Build Active Architecture Only" is set to "NO" for your project but also for your Pods project (selection with left panel).
Click on your project Scheme (top, near the stop button) and "Manage Scheme".
Check, select all your pods libraries and close.
Then, for all libs, select them (scroll the list) and build manually for the selected architecture.
Every time you change your architecture (simulator, device or for archive(Generic iOS Device)) you must do the above step: namely, manually build each libraries by selecting them in your scroll list one by one, and only than build and run your main project.
Seems a bit WTF, but it is the only way I resolve this issue...
I Had this Issue several Times with PODS Libraries.
Here is something you can Try:
Run pod cache clean --all and pod install again.
Check your Header Search Paths and Library Search Paths, Remove all entries and place $(PROJECT_DIR) in recursive mode and $(inherited) as a Second Entry
Go to your target Build Settings -> Other linker flags -> double click . Add $(inherited) to a new line.
Make sure Build Active Architecture Only is set to NO in the Pods project settings.
I'm thinking on two possibilities:
1) Install cocoapods-deintegrate project:
$ gem install cocoapods-deintegrate
Then run $ pod deintegrate, after that run $ pod install again. If it not works, then...
2) You can try open your Pods project and create new scheme for the target that you need, in this case for AFNetworking.
When the static library is created, then add it to your Frameworks references into your main project.
Hope that helps.
I have in project->TARGETS->Build Phases ->Link Binary With Libraries one "extra" framework that remains from recent project. Delate it and all run smoothly
Had a similar issue ... took a while to realize that I had updated my app's "iOS Deployment Target" to iOS 9.0, but the Pods project's "iOS Deployment Target" was still iOS 8.0!!!
I encountered this error when I downloaded some code from github. I tried to build .xcodeproj file but it failed giving the library not found error. I then opened .xcworkspace file and build that file first by clicking Product -> Build for -> Running. The workspace file built fine with no errors. Then in workspace file I changed scheme to the xcode project I was trying to build, and clicked Product -> Run. The app got built and ran with no errors.
I had this issue while using fastlane with a ReactNative project. I had added a dependency that required cocoapods.
My Fastfile looked like this:
...
gym(
scheme: "AppName",
project: "./ios/AppName.xcodeproj"
)
....
And had to change it to the workspace like this:
...
gym(
scheme: "AppName",
workspace: "./ios/AppName.xcworkspace"
)
...
For me all this thing not help. Only delete in Build settings project.
open xcode, from the top left select the pod library that is being shown as not found.Use 'Command B' to build this pod, then again select your target scheme and run.
For me this fixed it.
Use the xcworkspace to build instead of the xcproject?
This usually happens when using Cocoapods and you are building from the xcproject which doesn't know about the cocoapod libraries.

How to install VTK 6.1 for OSX 10.8 with Cocoa/XCode support?

The extremely helpful guidelines posted at http://www.vtk.org/Wiki/Cocoa_VTK and via the readme file by Sean McBride and Mike Jackson inside the VTK repo were slightly out of date for VTK 6.1. So in case this helps anybody, I'm posting instructions for installing VTK 6.1 on OSX 10.8 with support for the SimpleCocoaVTK Xcode project.
* Installing VTK 6.1 for OSX 10.8 with Cocoa support *
These instructions slightly modify Ryan Glover's instructions at http://www.vtk.org/Wiki/Cocoa_VTK and the README.rtf in the VTK/Examples/GUI/Cocoa/Documentation folder by Sean McBride and Mike Jackson.
Clone the VTK git repo into a directory of your choice:
cd /Users/you/
git clone https://github.com/Kitware/VTK.git
cd VTK
git checkout tags/v6.1.0
make a build directory
mkdir VTKBuild
cd VTKBuild
Run the VTK cmake script
You will now be inside /Users/you/VTK/VTKBuild, run cmake from here (using the parent directory's CMake files):
cmake ..
Edit lots of lines in the newly generated CMakeCache.txt (in the current VTKBuild directory). One issue I had was that there were error if I didn't use a full path for the CMAKE_INSTALL_PREFIX. So make sure to use "/Users/you/" instead of "~":
CMAKE_INSTALL_PREFIX:PATH=/Users/you/VTK/VTKBuild
BUILD_SHARED_LIBS:BOOL=OFF
CMAKE_BUILD_TYPE:STRING=Debug
VTK_USE_SYSTEM_ZLIB:BOOL=ON
CMAKE_OSX_ARCHITECTURES:STRING=i386;x86_64
CMAKE_OSX_SYSROOT:STRING=/Applications/XCode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
Compile the VTK project (this might take over an hour to run!):
make
Copy headers to an include directory:
make install
VTK should now be completely installed in the VTKBuild directory and ready to use in an XCode project!
Go to your finder, navigate to Users/you/VTK/Examples/GUI/Cocoa/ and double click to open SimpleCocoaVTK.xcodeproj in XCode.
In the XCode menubar (at the top of the screen) Go to Preferences->Locations->Source Trees and use the + button to add in two source trees:
vtk-debug-include vtk-debug-include Users/you/VTK/VTKBuild/include/vtk-6.1
vtk-debug-lib vtk-debug-lib Users/you/VTK/VTKBuild/lib
Click on the XCode project and delete all the references to vtk 6.0:
In the project view, select Targets->SimpleCocoaVTK and then press "Build Phases" and then open the "Link Binary With Libraries". Delete all the files that begin with "libvtk" and end with "6.0.a"
In the file view of the SimpleCocoaVTK project, hightlight and delete all the files in the vtk-libraries folder.
Make sure the XCode file view is active. Then in the finder, navigate to /Users/you/VTK/VTKBuild/lib, and select all the files that begin with "libvtk" and end with "6.1.a". Drag these files into the folder "vtk-libraries" in the XCode file view.
In XCode, do a Product->Clean
You can now build and run the sample SimpleCocoaVTK project.
I also had to set
VTK_WRAP_PYTHON:BOOL=ON
in CMakeCache.txt
It depends on what user you are too on your machine (computer) and the permissions relevant to that user. I did a find and replace on the CMakeCache.txt file and changed all /usr/local references to /Users/myusername/Develop/VTKInstall. That way everything's at your fingertips and you don't have to change permissions on things.
When you open up the Cocoa example make sure to set in you preferences these paths (e.g. Preferences->Locations->Source Trees). Also you'll need to re-import your vtk-libraries into the project.
I'm running Yosemite with XCode 6.1.1. I hope this helps someone!
If you get error messages likes this, when trying to build VTK:
#error: garbage collection is no longer supported
make[2]: *** Rendering/OpenGL/CMakeFiles/vtkRenderingOpenGL.dir/vtkCocoaRenderWindowInteractor.mm.o] Error 1
make1: *** [[Rendering/OpenGL/CMakeFiles/vtkRenderingOpenGL.dir/all] Error 2
You need to remove a flag in the source CMakeLists.txt:
#IF(APPLE)
SET(VTK_OBJCXX_FLAGS_DEFAULT "-fobjc-gc")
SET(VTK_REQUIRED_OBJCXX_FLAGS ${VTK_OBJCXX_FLAGS_DEFAULT} CACHE STRING "Extra flags for Objective-C++ compilation")
MARK_AS_ADVANCED(VTK_REQUIRED_OBJCXX_FLAGS)
ENDIF(APPLE)#
Either outcomment or delete it all together. Then run cmake again in an empty build directory. Check in the generated CMakeCache.txt in your build directory if it contains a key like VTK_REQUIRED_OBJCXX_FLAGS, it shouldn´t, try running cmake in an empty build directory again.
This 'bug' maybe fixed in future VTK versions.
Source: [Solved] Build Qt 5.2.1 + VTK 6.1.0 + CMake 2.8.12.2

Xcode linker Directory not found for option

Xcode 4 is throwing me a warning about directory not found for option '-L/Users/t2wu/Documents/blah blah'. Yes it shouldn't be found because I removed it. I remove the directory and I also removed the directory setting in both the target and the project library search path. I also remove the .a file which I was linking before from the "Link binaries with Libraries". It compiles fine, it just gives me the warning. Why is it still having the -L flag?
Check the Build settings tab and make sure that the "Library search paths" option is empty.
At last resort, fire up Terminal and cd to the app project directory (appname.xcodeproj) and do a fgrep for the erroneous search path. I've found some of these lurking in the project.pbxproj file; ended up editing the file manually to get rid of them. (Of course you should make a copy of the file before doing so, in case you trash the project file.)
It'd also be worthwhile to do a "clean" on the project. How to Empty Caches and Clean All Targets Xcode 4.
I had the same issue in my project, it contains multiple custom framework created by me and the project. My issue is resolved by removing 'Framework search Paths' and 'Library Search Paths' from the target which has this issue.
In my case in targets -> build settings I removed searchpaths for which errors occured. Then removed libraries from project and added them again.
You may need to clear the Search Paths for the Tests target as well as the main project. This had me stumped for a little while.
I checked the library search path
I went to Build settings -> Search Paths change the "Framework Search Paths" to $(inherited)...that solved my problem
Sometimes, this error occurs if you open Project.xcodeprojinstead of Project.xcworkspace. Check your project directory and make sure to open Project.xcworkspace.

Resources