I am using Cocoapods in my project, but I also want to use frameworks that are not managed by Cocoapods. I recently tried to switch to frameworks using the use_frameworks! command in my podfile, but the result is that the build fails because it can't find a header from my third-party framework. In the xcconfig file for my project, I have FRAMEWORK_SEARCH_PATHS = $(inherited) $(PROJECT_DIR)/vendor, which worked in the past (vendor being where the .framework file is stored).
I don't know much about this topic; my attempt at solving this was to add a HEADER_SEARCH_PATHS setting to the xcconfig file with the same settings as the FRAMEWORK_SEARCH_PATHS, which did not solve the problem. Any help would be appreciated.
EDIT: upon further investigation into the problem I think I better understand what is causing this behavior, though I'm no closer to a resolution. The Xcconfig configuration I'm using is set up approximately like this for the debug scheme:
Pods-ProjectName.debug.xcconfig -- the CocoaPods created xcconfig file for the project. Contents are roughly as follows:
FRAMEWORK_SEARCH_PATHS = "$PODS_FRAMEWORK_BUILD_PATH"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
LD_RUNPATH_SEARCH_PATHS = $(inherited) '#executable_path/Frameworks' '#loader_path/Frameworks'
OTHER_CFLAGS = $(inherited) -iquote "$PODS_FRAMEWORK_BUILD_PATH/x.framework/Headers" -iquote "$PODS_FRAMEWORK_BUILD_PATH/y.framework/Headers" -iquote "$PODS_FRAMEWORK_BUILD_PATH/z.framework/Headers" -iquote "$PODS_FRAMEWORK_BUILD_PATH/a.framework/Headers"
OTHER_LDFLAGS = $(inherited) -ObjC -framework "x" -framework "y" -framework "z" -framework "a"
OTHER_LIBTOOLFLAGS = $(OTHER_LDFLAGS)
PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods-ProjectName
PODS_ROOT = ${SRCROOT}/Pods
ProjectName.xcconfig - contents are as follows:
APPLICATION_EXTENSION_API_ONLY = YES
FRAMEWORK_SEARCH_PATHS = $(inherited) $(PROJECT_DIR)/vendor
WARNING_CFLAGS = $(inherited) -include "$(SOURCE_ROOT)/ProjectName/ProjectNameVersion.h"
INFOPLIST_FILE = ProjectName/Info.plist
PRODUCT_NAME = ProjectName
SKIP_INSTALL = YES
ProjectNameDebug.xcconfig - includes both of the prior xcconfig files, is the project's xcconfig file. In case it matters, here's the contents:
#include "ProjectName.xcconfig"
<h1>include "../Pods/Target Support Files/Pods-ProjectName/Pods-ProjectName.debug.xcconfig"
The thing is, what I'm actually seeing when I open the xcporoject file and go to Build Settings->Framework Search Paths is bulid/Debug-iphoneos/Pods-ProjectName. So somehow my vendor search path is getting overwritten.
Apologies for the formatting, SO didn't want to highlight this stuff as code, and in some cases even tried to make it bold...
I have a really hard time install RestKit into my project using CocoaPods. I get the not found error.
My Pods.xcconfig looks like this:
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers" "${PODS_ROOT}/Headers/AFNetworking" "${PODS_ROOT}/Headers/ISO8601DateFormatterValueTransformer" "${PODS_ROOT}/Headers/RKValueTransformers" "${PODS_ROOT}/Headers/RestKit" "${PODS_ROOT}/Headers/RestKit/CoreData" "${PODS_ROOT}/Headers/RestKit/Network" "${PODS_ROOT}/Headers/RestKit/ObjectMapping" "${PODS_ROOT}/Headers/RestKit/Support" "${PODS_ROOT}/Headers/SDWebImage" "${PODS_ROOT}/Headers/SOCKit" "${PODS_ROOT}/Headers/SSKeychain" "${PODS_ROOT}/Headers/SVProgressHUD" "${PODS_ROOT}/Headers/TTTAttributedLabel" "${PODS_ROOT}/Headers/TransitionKit" "${PODS_ROOT}/Headers/Vendor/LibComponentLogging/Core" "${PODS_ROOT}/Headers/Vendor/LibComponentLogging/NSLog"
OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers" -isystem "${PODS_ROOT}/Headers/AFNetworking" -isystem "${PODS_ROOT}/Headers/ISO8601DateFormatterValueTransformer" -isystem "${PODS_ROOT}/Headers/RKValueTransformers" -isystem "${PODS_ROOT}/Headers/RestKit" -isystem "${PODS_ROOT}/Headers/RestKit/CoreData" -isystem "${PODS_ROOT}/Headers/RestKit/Network" -isystem "${PODS_ROOT}/Headers/RestKit/ObjectMapping" -isystem "${PODS_ROOT}/Headers/RestKit/Support" -isystem "${PODS_ROOT}/Headers/SDWebImage" -isystem "${PODS_ROOT}/Headers/SOCKit" -isystem "${PODS_ROOT}/Headers/SSKeychain" -isystem "${PODS_ROOT}/Headers/SVProgressHUD" -isystem "${PODS_ROOT}/Headers/TTTAttributedLabel" -isystem "${PODS_ROOT}/Headers/TransitionKit" -isystem "${PODS_ROOT}/Headers/Vendor/LibComponentLogging/Core" -isystem "${PODS_ROOT}/Headers/Vendor/LibComponentLogging/NSLog"
OTHER_LDFLAGS = -ObjC -framework CFNetwork -framework CoreData -framework CoreGraphics -framework CoreText -framework Foundation -framework ImageIO -framework MobileCoreServices -framework QuartzCore -framework Security -framework SystemConfiguration
PODS_ROOT = ${SRCROOT}/Pods
Podfile like so:
platform :ios, '7.0'
pod 'TTTAttributedLabel'
pod 'SVProgressHUD', :head
pod 'SDWebImage', '~>3.6'
pod 'SSKeychain'
pod 'RestKit', '0.23.1'
My Project settings in in the other linker flags includes:
$(inherited)
And the header search paths does also include:
$(inherited)
"$(BUILT_PRODUCTS_DIR)/../../Headers"
My target configuration is like so:
How can I fix this issue?
In my case this issue was related to pods configuration.
Step to resolve.
IMP: Backup your project before doing any configuration changes.
Find the file where the variable PODS_ROOT is defined in your project. It will be defined under Pods-<Project Name>.debug.xcconfig and Pods-<Project Name>.release.xcconfigfiles.
Reveal/Show both files in Finder , it will be under the folder /Pods/Target Support Files/Pods-<Project Name>/
Delete both files from your project (DO NOT trash, only remove the reference)
Now from your project navigator , open build-debug.xcconfig
Replace the following line ,
#include "../pods-debug.xcconfig"
with the following line,
#include "../Pods-<Your Project Name>.debug.xcconfig"
and in build-release.xcconfig replace the following line ,
#include "../pods-release.xcconfig"
with the following line,
#include "../Pods-<Your Project Name>.release.xcconfig"
Replace the original file pods-debug.xcconfig and pods-release.xcconfig files under your project folder with the files Pods-<Your Project Name>.debug.xcconfig and Pods-<Your Project Name>.release.xcconfig respectively from the folder /Pods/Target Support Files/Pods-<Project Name>/.
Add back the new configuration files Pods-<Your Project Name>.debug.xcconfig and Pods-<Your Project Name>.release.xcconfig to your project.
Confirm both your project and target is referring to pods-debug.xcconfig/pods-release.xcconfig (Select Project File then select 'info' tab, under that expand 'Configurations')
Confirm 'Build Settings/Header Search Paths' contains $(inherited)
Reopen your project and do a clean build.
Explaining the issue
The pod configuration was not properly loaded to your project , to test this you can simply add "$(PODS_ROOT)/test" under 'Build Settings/Header Search Paths', you can see it is resolving to '/test' , that means the variable PODS_ROOT was not defined and hence it is resolving to empty string. That means the config file where PODS_ROOT is defined not loaded to project settings. Now check the config file set in your Xcode project (Select Project File then select 'info' tab, under that expand 'Configurations') it is referring to build.xcconfig and build-debug.xcconfig/build-release.xcconfig. These files includes the pod config files, but the included config files pods-debug.xcconfig/pods-release.xcconfig doesn't contain the required pod config details. So, now we replaced this with correct config file. You can also try copy paste the content of config files so that we can avoid replacing the files.
I have a project file with a Podfile that looks like this:
platform :ios, '7.0'
def import_pods
pod 'Specta', '0.1.8'
pod 'Expecta', '0.2.1'
pod 'RestKit', '0.20.3'
pod 'MagicalRecord', '2.1'
pod 'RestKit/Testing', '0.20.3'
end
link_with 'LocalMedTests'
import_pods
When I run pod install, it generates the Podfile.lock, Pods directory, and workspace for my project. When I open the workspace to build it, I get errors like this: 'RestKit.h' file not found.
It seems to only be an issue for RestKit but I can't get past those errors to see if there are more. The restkit headers are in Pods/Headers. They're properly included in Pods.xcconfig. Here it is for good measure:
FRAMEWORK_SEARCH_PATHS = $(inherited) "$(SDKROOT)/Developer/Library/Frameworks" "$(DEVELOPER_LIBRARY_DIR)/Frameworks"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers" "${PODS_ROOT}/Headers/AFNetworking" "${PODS_ROOT}/Headers/Expecta" "${PODS_ROOT}/Headers/MagicalRecord" "${PODS_ROOT}/Headers/RestKit" "${PODS_ROOT}/Headers/RestKit/RestKit" "${PODS_ROOT}/Headers/RestKit/RestKit/CoreData" "${PODS_ROOT}/Headers/RestKit/RestKit/Network" "${PODS_ROOT}/Headers/RestKit/RestKit/ObjectMapping" "${PODS_ROOT}/Headers/RestKit/RestKit/Support" "${PODS_ROOT}/Headers/RestKit/RestKit/Testing" "${PODS_ROOT}/Headers/SOCKit" "${PODS_ROOT}/Headers/Specta" "${PODS_ROOT}/Headers/TransitionKit"
OTHER_LDFLAGS = -ObjC -framework CFNetwork -framework CoreData -framework Foundation -framework MobileCoreServices -framework Security -framework SenTestingKit -framework SystemConfiguration
PODS_ROOT = ${SRCROOT}/Pods
I've tried cleaning and cleaning the build folder. It doesn't matter - I always get the header not found error.
I should also add that all of the header directories specified by Pods.xcconfig are included in the target as they should be.
Any ideas about this? I've been using CocoaPods in this project for a couple of months with no issue, did something change recently?
This solved my Problem
In HEADER_SEARCH_PATHS Under your Project Build Setting add the $(inherited)
Also DO this for all TAGETS
Change Arcgitectures to Standard armv7
https://stackoverflow.com/a/12142790/1294448
For me, the problem was with Other Linker Flags and Runpath Search Paths, which weren't inheriting the settings defined on xcconfig. The following adjustments solved my problem:
Other Linker Flags:
$(inherited)
Runpath Search Paths:
$(inherited)
#executable_path/Frameworks
I pod install NYXImagesKit to my example project, it builds successfully but after the simulator lunches, there is error in Xcode:
/XXX.m:17:9: 'NYXImagesKit.h' file not found
Everything is fine, the simulator works fine, the only problem is that the build error is there but no link error, it is very strange.
I have ${PODS_HEADERS_SEARCH_PATHS} defined in HEADER SEARCH PATH, and the pod.config is as follow:
ALWAYS_SEARCH_USER_PATHS = YES
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = ${PODS_HEADERS_SEARCH_PATHS} $(SDKROOT)/usr/include/libxml2
OTHER_LDFLAGS = -ObjC -lxml2 -framework Accelerate -framework AssetsLibrary -framework CoreImage -framework ImageIO -framework MobileCoreServices -framework QuartzCore
PODS_BUILD_HEADERS_SEARCH_PATHS = "${PODS_ROOT}/BuildHeaders" "${PODS_ROOT}/BuildHeaders/NYXImagesKit" "${PODS_ROOT}/BuildHeaders/hpple"
PODS_HEADERS_SEARCH_PATHS = ${PODS_PUBLIC_HEADERS_SEARCH_PATHS}
PODS_PUBLIC_HEADERS_SEARCH_PATHS = "${PODS_ROOT}/Headers" "${PODS_ROOT}/Headers/NYXImagesKit" "${PODS_ROOT}/Headers/hpple"
PODS_ROOT = ${SRCROOT}/Pods
I'm surprised the simulator launches if it's showing you a build issue. You might want to try cleaning your project from Product -> Clean in the menu bar. Or deleting your derived data from the Organizer. Also verify that CocoaPods has the newest version with pod --version (right now it is 0.21.0) otherwise update with [sudo] gem update
I have a project in Xcode 4 (the latest non-beta version) that builds fine when built in Xcode itself. Specifically, the Ld command correctly uses the derived data directory (where build products, including a dependent static library, are placed).
However, when I build the same project from the command line, the Ld command fails, as it is trying to use the /build folder within the project, which is not being populated.
I've tried adjusting every build setting I know about, both in the parent and the dependent project.
Any ideas on where to start debugging this? I can provide more info as needed.
Edit 1: Full Xcode build command:
xcodebuild -project AppName.xcodeproj -target AppName -configuration "Config Name"
Where AppName and Config Name are both the correct values for the build.
Edit 2: Link (Ld) commands.
When built in Xcode (this works):
Ld /Users/james/Library/Developer/Xcode/DerivedData/AppName-apkmkuhwuccsbpblulxcsafyxkwa/Build/Products/Debug-iphonesimulator/AppName.app/AppName normal i386
cd /Users/james/Code/ClientName-Depot/NameOfProject/trunk/AppName
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/opt/local/bin:/usr/local/git/bin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk -L/Users/james/Library/Developer/Xcode/DerivedData/AppName-apkmkuhwuccsbpblulxcsafyxkwa/Build/Products/Debug-iphonesimulator -L/Users/james/Code/ClientName-Depot/NameOfProject/trunk/AppName -F/Users/james/Library/Developer/Xcode/DerivedData/AppName-apkmkuhwuccsbpblulxcsafyxkwa/Build/Products/Debug-iphonesimulator -filelist /Users/james/Library/Developer/Xcode/DerivedData/AppName-apkmkuhwuccsbpblulxcsafyxkwa/Build/Intermediates/AppName.build/Debug-iphonesimulator/AppName.build/Objects-normal/i386/AppName.LinkFileList -mmacosx-version-min=10.6 -lxml2 -all_load -ObjC -licucore -Xlinker -objc_abi_version -Xlinker 2 -lMyClientLibrary -lxml2 -lsqlite3.0 -framework Security -framework MessageUI -framework QuartzCore -framework MediaPlayer -framework MapKit -framework CoreLocation -framework AudioToolbox -lz.1.2.3 -framework MobileCoreServices -framework SystemConfiguration -framework CFNetwork -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/james/Library/Developer/Xcode/DerivedData/AppName-apkmkuhwuccsbpblulxcsafyxkwa/Build/Products/Debug-iphonesimulator/AppName.app/AppName
When built from command line using build command above (this fails):
Ld "build/AppName.build/Prod Ad Hoc-iphoneos/AppName.build/Objects-normal/armv6/AppName" normal armv6
cd /Users/james/Code/ClientName-Depot/NameOfProject/trunk/AppName
setenv IPHONEOS_DEPLOYMENT_TARGET 4.0
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin:/opt/local/bin"
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk "-L/Users/james/Code/ClientName-Depot/NameOfProject/trunk/AppName/build/Prod Ad Hoc-iphoneos" -L/Users/james/Code/ClientName-Depot/NameOfProject/trunk/AppName "-F/Users/james/Code/ClientName-Depot/NameOfProject/trunk/AppName/build/Prod Ad Hoc-iphoneos" -filelist "/Users/james/Code/ClientName-Depot/NameOfProject/trunk/AppName/build/AppName.build/Prod Ad Hoc-iphoneos/AppName.build/Objects-normal/armv6/AppName.LinkFileList" -dead_strip -lxml2 -all_load -ObjC -licucore -miphoneos-version-min=4.0 -lMyClientLibrary -lxml2 -lsqlite3.0 -framework Security -framework MessageUI -framework QuartzCore -framework MediaPlayer -framework MapKit -framework CoreLocation -framework AudioToolbox -lz.1.2.3 -framework MobileCoreServices -framework SystemConfiguration -framework CFNetwork -framework UIKit -framework Foundation -framework CoreGraphics -o "/Users/james/Code/ClientName-Depot/NameOfProject/trunk/AppName/build/AppName.build/Prod Ad Hoc-iphoneos/AppName.build/Objects-normal/armv6/AppName"
Which returns:
ld: library not found for -lMyClientLibrary
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1
Ok, so nearly 6 (billable) hours later, I've gotten the build to work correctly in Xcode and on the command line (and on the build server, the whole point of this exercise).
Along the way I would fix one problem just to cause another - I would apparently fix the linker/Ld problem, only to cause problems in compilation ("SomeClass undeclared (first use in this function)" or "SomeHeader.h: No such file or directory" errors were common).
It was one of those times that I adjusted nearly every setting I could find, so it's hard to say what exactly what wrong and what exactly fixed it.
Things I think might have helped are are as follows:
Converted build to use an Xcode workspace & scheme (instead of project & target)
Rearranged workspace to have the App project and static library as siblings (not as parent/child)
Changed Xcode and workspace settings to use build locations specified in targets
Change Build Products Path for App and Library to use ../build (both project files are contained in sibling subfolders of a master directory, so having them build into the same folder solved the original linker/Ld command problem, I think)
Edited the App scheme to explicitly build the Library target, and build it before the App target
In the Build Phases for the App target, explicitly add the Library under "Link Binary With Libraries"
Change the location type of the Library's .a file reference to "Relative to Build Products"
Added a "Copy Headers" build phase to the Library project, added the appropriate headers to the Public section
Changed the Public Headers Folder Path of the Library project to "/include"
Changed the Installation Directory of the Library to $(BUILT_PRODUCTS_DIR)
Changed the Library Search Paths and the User Header Search Paths of the App target to $(BUILT_PRODUCTS_DIR) (recursive)
Added a Clean command before the build on my Jenkins build server
Added explicit SDK and Arch arguments to the build command
Removed spaces from build configuration name
Final build command looks like this:
xcodebuild -workspace ClientName.xcworkspace -scheme AppName -configuration "ProdAdHoc" -sdk iphoneos -arch "armv6 armv7"
Some useful resources I used while debugging this issue:
http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/
https://devforums.apple.com/thread/91711?start=25&tstart=0
Anyway, I hope I've peppered enough keywords above that anybody who has any similar build issues in the future stumbles upon this and finds it useful. I have no clue how a workflow I did many times in Xcode 3.x got so messed up when I moved to Xcode 4, here's hoping Apple is able to clean this up in future releases.
This was a heck of a learning experience for me, and going through all of this did seem to clear up issues with autocomplete I was having beforehand. I will say things could have been much worse; I could still be developing for SharePoint.
I ran in to the same issue yesterday and was able to work it out. In an effort to narrow down what worked for James, I'll point to what I had to do. I had to add a workspace and switch to running xcodebuild with workspace/scheme instead of project/target.
Using workspace/scheme forced xcodebuild to use the DerivedData folder instead of the build output folder under the main project. This allowed the linker to find the associated static library.
This blog post was hugely helpful:
http://blog.carbonfive.com/2011/05/04/automated-ad-hoc-builds-using-xcode-4/
I got this error when I was experimenting with my files I add the #implementation to the .h file and left the .m file empty. I don't believe this is your error but if anyone else gets it maybe check that you haven't done this.
Check if you didn't import the .m files in your header files! Changing .m to .h fixed this for me!
I don't know if this will work for you but in my case, I had more than one main.m file. All I had to do was detach one of the main.m from the target and it worked. Make sure you don't have more than one main.m in your project.
If you look at the log of the build, asking to see all messages, you should see a terse line that says "link ..." that has little in the way of details. However if you right click that line and select "expand all transcripts" you get a very detailed line telling you what command was issued from within XCode.
That should help you to debug the issue.
Dave
I had a similar exception encountered,
it turn out that i got some (null) reference in project.pbxproj
after I clean up those null reference in the project.pbxproj, the command line build was success just like the xcode previously does.
Take a look at Xcode 4 project: utility to clean up pbxproj file?
utility-to-clean-up-pbxproj-file
for more reference
All of a sudden I got the same problem after a Clean, at first I panicked wen I watched:
linker command failed with exit code 1 (use -v to see invocation)
... but it turned to be really easy to fix, no command line needed!
I clicked on my project's root (the one on the top with the blueprint icon with an "A") in the Navigator, then clicked the PROJECT section (you can click on the TARGET section as well) and then clicked the button in the bottom-middle called "Validate Settings".
XCode itself validated the project files and told me that the problem was a duplicated target definition, and offered to fix it... and voilá, the problem its gone!
Good luck!
I resolve the issue by going to "Library search path", and make sure all entries are correct.
Personally, I had this issue when I was developing a static library. I had the static library target with all the production code, and a test target that pulled in the MyStaticLib.a file as a framework.
Tests ran just fine in Xcode, but not in the terminal using xcodebuild. The problem ended up being that the static library target was compiling for Standard architectures, while the test target wanted to compile for Standard architectures (including 64-bit). Switching the test target to Standard architectures fixed everything.