Xcode custom build configuration causes “library/f

2019-01-13 04:34发布

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:

  • force libraries to be placed in the build configuration folder of the app's target
  • run a post-compile & pre-link script that copies each library to the build configuration folder
  • specify a relative path to the libraries
  • use a different macro other than $BUILT_PRODUCTS_DIR for -force_load
  • a linker flag like -WTFmake-all-problems-go-away

Excuse me, but I have to say this … ARGH! :)

7条回答
啃猪蹄的小仙女
2楼-- · 2019-01-13 04:46

Usually I have an AppStore scheme (mapped to my AppStore config).

One thing that happened to me, was this case sensitive issue that was making Cocoapods to generate a build folder for Pods.build inside Release-iphonesimulator (as a fallback) instead of AppStore-iphonesimulator.

I guess I miss-clicked when I linked the scheme and config and only removing it and re-adding made me understand what went wrong. Check the diff.

sensitive issue

I was using cocoapods 0.38.2, so this was clearly a user mis-configuration and not a Cocoapods issue that was resolved on 0.34

查看更多
Rolldiameter
3楼-- · 2019-01-13 04:47

I have not found a way to do this, unfortunately. The best workaround I can find is to add new targets rather than new build configurations. So for example in one of my projects I have only Release and Debug configurations, but I have extra targets called "MyProject - app store" and "MyProject - ad hoc". This will only be possible if you have control of the project file, of course.

Having duplicated targets sitting around is annoying in the extreme because you can add files to one target and forget to add them to the others, and you won't know until you try and build it. But it does build, which is a win (with xcode anyhow).

A similar question I asked a while ago: What is the correct way to set build configurations in an ios project using static libraries for creating an archive in xcode 4?

查看更多
霸刀☆藐视天下
4楼-- · 2019-01-13 05:00

My framework is built using another SDK project inside my app project. First I have a "Debug" and "Release", then I add a new "TestFlight" configuration. I can't archive with that new one. I ended up adding a new build configuration with the same name in the SDK project. In other words, I ended up adding "TestFlight" configuration to BOTH my app and SDK projects. Now Archive works.

I'm not sure if it's the best way to do it. But it looks clean enough to me for now. :)

Oh, and for Cocoapods, after you duplicate the configuration, if you run pod install right away you will get this yellow warning:

[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target ...

You have to go to the Project, "Info" tab, "Configurations" section, select the new configuration you just created, and set "Pods.release" of all targets to "None" first. After that, you can run pod install safely.

查看更多
5楼-- · 2019-01-13 05:04

You could add CONFIGURATION_BUILD_DIR=/Some/Shared/Dir before running xcodebuild. For example:

cd SOURCE_DIR
xcodebuild  -workspace YourProject.xcworkspace -scheme YourScheme -configuration AdHoc -sdk iphoneos clean build CONFIGURATION_BUILD_DIR="`pwd`"/build
查看更多
贪生不怕死
6楼-- · 2019-01-13 05:07

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
查看更多
孤傲高冷的网名
7楼-- · 2019-01-13 05:07

I have a similar problem using CocoaPods and trying to have more than one Adhoc (or Enterprise, or Beta) configurations.

Here is what seems to work (let's say that both projects are lying in the same xcworkspace):

  • Add the subproject generated lib to the mainproject Link Binary with Libraries.

  • As the configuration Adhoc is not known by the subproject, Xcode will use the Release config as a fallback (or maybe the first config of the list) when building it.

  • The linker will complain because it cannot find the lib… ok, let's handle this one.

  • Add a Run Script build phase to the mainproject, right after the Target Dependencies phase. Enter this script:

if [ "$CONFIGURATION" = "Adhoc" ]; then
    echo "====================================="
    echo "Copying libPods Release into the Adhoc product build dir!"
    echo "====================================="
    cp "$BUILT_PRODUCTS_DIR/../Release-$PLATFORM_NAME/libPods.a" "$BUILT_PRODUCTS_DIR"
else
    echo "No manual lib copy."
fi

This will copy the lib generated by the subproject Release build (which will happen when mainproject is built) in the Adhoc build directory, so that the linker will find the lib. And we should be good to go! Yeah!

查看更多
登录 后发表回答