xcode 7.2: Failed to build framework from command line, works well from IDE

I have just updated my Xcode to version 7.2. Now I try to build a framework ( https://github.com/onevcat/Kingfisher ) from command line using xcodebuild

xcodebuild -project Kingfisher.xcodeproj -scheme Kingfisher -sdk iphonesimulator


but have this error

.... /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/CAMediaTiming.h:6:9: note: in file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/CAMediaTiming.h:6:
#import         ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/CABase.h:11:10: error: could not build module 'Darwin'
#include          ^
/Users/atran/Desktop/Repos/DSA_Working_Directory/Libs/Kingfisher/Kingfisher/Kingfisher.h:27:9: note: while building module 'UIKit' imported from /Users/atran/Desktop/Repos/DSA_Working_Directory/Libs/Kingfisher/Kingfisher/Kingfisher.h:27:
#import         ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UICollectionViewLayout.h:11:9: note: while building module 'QuartzCore' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UICollectionViewLayout.h:11:
#import         ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/CAEAGLLayer.h:7:9: note: while building module 'OpenGLES' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/System/Library/Frameworks/QuartzCore.framework/Headers/CAEAGLLayer.h:7:
#import         ^
:1:9: note: in file included from :1:
#import "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/System/Library/Frameworks/OpenGLES.framework/Headers/EAGL.h"
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/System/Library/Frameworks/OpenGLES.framework/Headers/EAGL.h:8:10: error: could not build module 'Foundation'
#include          ^
:1:9: note: in file included from :1:
#import "/Users/atran/Desktop/Repos/DSA_Working_Directory/Libs/Kingfisher/Kingfisher/Kingfisher.h"
        ^
/Users/atran/Desktop/Repos/DSA_Working_Directory/Libs/Kingfisher/Kingfisher/Kingfisher.h:27:9: error: could not build module 'UIKit'
#import         ^
:0: error: could not build Objective-C module 'Kingfisher'


Everything worked well in XCode 7.1. so there must be something changed in XCode 7.2.


This happens also only when I build the framework from command line for iphonesimulator target. It works well when build against iphoneos sdk.


Anyone has a clue?

Replies

We have isolated it to line 707 of the cdefs file. It seems that the following condition fails:


Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk/usr/include/sys/cdefs.h : 707


/

* Architecture validation for current SDK

*/

#if !defined(__sys_cdefs_arch_unknown__) && defined(__i386__)

#elif !defined(__sys_cdefs_arch_unknown__) && defined(__x86_64__)

#else

#error Unsupported architecture

#endif

#endif / !_CDEFS_H_ */


it seems that the arch unknown condition is true. I am unable to find where the __sys_cdefs_arch_unknown__ is set.

+1

__sys_cdefs_arch_unknown__ has tested as false, but we cannot find the platform setting constant. We have been able to find that it's none of the following


__arm__

__arm64__

__i386__

__x86_64__


but if(as a test) we hard code __x86_64__ immediately above the code mentioned above and test,


/

* Architecture validation for current SDK

*/

//TEST

#define __x86_64__ 1

//ENDTEST

#if !defined(__sys_cdefs_arch_unknown__) && defined(__i386__)

#elif !defined(__sys_cdefs_arch_unknown__) && defined(__x86_64__)

#else

#error Unsupported architecture

#endif

#endif / !_CDEFS_H_ */


the build runs fine. It seems that the process that sets the platform variable is not running properly?

Same issue here with xcodebuild 7.2

Same problem here. https://openradar.appspot.com/23857648

Adding '-destination' as a workaround seems to work for me.


This worked for me after I added the destination:

xcodebuild clean build -workspace ${WORKSPACE} -scheme ${TARGET_NAME} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" -destination 'platform=iOS Simulator,name=iPhone 6'

To build for a device platform rather than just simulator, you can use the following destination: "platform=iOS,name=YOURPHONESNAME" while your phone is plugged in. You can also specify it by UUID


get a list from a terminal like this:


instruments -s devices


This also works for apple TV and watch OS

Is there any way to get the destination automatically?


I am using a buildscript to generate a framework


#Credit: set -e
# If we're already inside this script then die
if [ -n "$RW_MULTIPLATFORM_BUILD_IN_PROGRESS" ]; then
exit 0
fi
export RW_MULTIPLATFORM_BUILD_IN_PROGRESS=1
RW_FRAMEWORK_NAME=${PROJECT_NAME}
RW_INPUT_STATIC_LIB="lib${PROJECT_NAME}.a"
RW_FRAMEWORK_LOCATION="${BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.framework"
function build_static_library {
    # Will rebuild the static library as specified
    #     build_static_library sdk
    echo 'lll building static lib'+ ${1};
    
    xcrun xcodebuild \
    -workspace "${PROJECT_DIR}/${PROJECT_NAME}.xcworkspace" \
    -scheme "${TARGET_NAME}" \
    -configuration "${CONFIGURATION}" \
    -sdk "${1}" \
    -destination 'platform=iOS Simulator,name=iPhone 6' \
    ONLY_ACTIVE_ARCH=NO \
    BUILD_DIR="${BUILD_DIR}" \
    OBJROOT="${OBJROOT}" \
    BUILD_ROOT="${BUILD_ROOT}" \
    SYMROOT="${SYMROOT}" $ACTION
}
function make_fat_library {
    # Will smash 2 static libs together
    #     make_fat_library in1 in2 out
    xcrun lipo -create "${1}" "${2}" -output "${3}"
}
# 1 - Extract the platform (iphoneos/iphonesimulator) from the SDK name
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]; then
RW_SDK_PLATFORM=${BASH_REMATCH[1]}
echo 'lll RW SDK platform' + $RW_SDK_PLATFORM
else
echo "Could not find platform name from SDK_NAME: $SDK_NAME"
exit 1
fi
# 2 - Extract the version from the SDK
if [[ "$SDK_NAME" =~ ([0-9]+.*$) ]]; then
RW_SDK_VERSION=${BASH_REMATCH[1]}
else
echo "Could not find sdk version from SDK_NAME: $SDK_NAME"
exit 1
fi
# 3 - Determine the other platform
if [ "$RW_SDK_PLATFORM" == "iphoneos" ]; then
RW_OTHER_PLATFORM=iphonesimulator
else
RW_OTHER_PLATFORM=iphoneos
fi
echo 'lll otherPlatform' + $RW_OTHER_PLATFORM
# 4 - Find the build directory
if [[ "$BUILT_PRODUCTS_DIR" =~ (.*)$RW_SDK_PLATFORM$ ]]; then
RW_OTHER_BUILT_PRODUCTS_DIR="${BASH_REMATCH[1]}${RW_OTHER_PLATFORM}"
else
echo "Could not find other platform build directory."
exit 1
fi
# Build the other platform.
#build_static_library "${RW_OTHER_PLATFORM}${RW_SDK_VERSION}"
#build_static_library "$RW_OTHER_PLATFORM"
# If we're currently building for iphonesimulator, then need to rebuild
#   to ensure that we get both i386 and x86_64
if [ "$RW_SDK_PLATFORM" == "iphonesimulator" ]; then
build_static_library "${SDK_NAME}"
#build_static_library "iphoneos"
fi
# Join the 2 static libs into 1 and push into the .framework
make_fat_library "${BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}"
# Ensure that the framework is present in both platform's build directories
cp -a "${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.framework/Versions/A/${RW_FRAMEWORK_NAME}"
# Copy the framework to the user's desktop
ditto "${RW_FRAMEWORK_LOCATION}" "${HOME}/Desktop/${RW_FRAMEWORK_NAME}.framework"

Another workaround is to pass PLATFORM_NAME=iphonesimulator to xcodebuild, in addition to -sdk iphonesimulator.


BTW Xcode 7.2.1 just came out and the issue is still NOT fixed. Good job, Apple.