I have a workspace with a project which links with the static libraries in another project (which is also in the workspace). It's a problem in Kobold2D I haven't been able to resolve, even though I understand the cause, and I suppose it's similar to this question.
The project targets and the static library targets all have the Debug and Release build configurations. All is well.
Now someone adds a new build configuration in the project and names it Ad-Hoc for example. Now the project's target builds the Ad-Hoc configuration, however the static libraries have no such configuration. Apparently they then default to building the Release configuration.
At the end, when the linker is supposed to bring everything together, it fails:
ld: library not found for -lbox2d-ios Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang++ failed with exit code 1
For forcibly loaded libraries via -force_load $(BUILT_PRODUCTS_DIR)/libSomeLib.a
the error is similar but says "file not found". I should note that the library "libbox2d-ios.a" is in the "link binary with libraries" build phase list.
Obviously the problem is that the linker is assuming that the libraries are in the Ad-Hoc-iphoneos folder in the BUILT_PRODUCTS_DIR while they are actually in the Release-iphoneos folder because they have no Ad-Hoc build configuration.
How can I slap the linker in the face and tell him to get the libraries where they are? Preferably I'm looking for a solution that works for both cases, ie libraries added the standard way (link binary with libraries build phase) and libraries that need an additional -force_load to work.
I'm hoping that there's some way to:
Excuse me, but I have to say this … ARGH! :)
Xcode Configuration file (. xcconfig) is actually a key/value based file. You can store your build settings in the form of key/value pairs, similar to what you did in dictionaries. By using a . xcconfig file, it is very easy to define build parameters for each build.
You can change it easily. On the top menu click on your project name. In my case, it's BuildVersion (the name of the project). On the left panel select Run and change Build Configuration to Release.
As said in similar question iOS Static Library as a Subproject of a Project That Has Custom Build Configurations?, the fix is to add this line
$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)
to your target's Framework Search Paths
, Header Search Paths
and/or Library Search Paths
Here's something that works for me.
In the project with the Adhoc build configuration, override the "Per-configuration Build Products Path" (CONFIGURATION_BUILD_DIR) and "Per-configuration Intermediate Build Files Path" (CONFIGURATION_TEMP_DIR) for the Adhoc build configuration to use the same folder as the release configuration.
Adhoc: CONFIGURATION_BUILD_DIR = $(SYMROOT)/Release$(EFFECTIVE_PLATFORM_NAME) Adhoc: CONFIGURATION_TEMP_DIR = $(PROJECT_TEMP_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)
Now when you do an Adhoc build, Xcode will put libFoo.a and Bar.app in the Release-iphoneos folder. The linker will be happy and you can use -force_load $(BUILT_PRODUCTS_DIR)/libFoo.a as usual.
Alternatively, you can add the Release-iphoneos folder to the library search paths for the Adhoc build configuration:
Adhoc: LIBRARY_SEARCH_PATHS = $(inherited) $(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)
But then you'll have to set a different -force_load for each build configuration:
Debug: OTHER_LINKER_FLAGS = $(inherited) -force_load $(BUILT_PRODUCTS_DIR)/libFoo.a Adhoc: OTHER_LINKER_FLAGS = $(inherited) -force_load $(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME) Release: OTHER_LINKER_FLAGS = $(inherited) -force_load $(BUILT_PRODUCTS_DIR)/libFoo.a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With