30

I updated my Xcode but not able to build. It's failing with:

<unknown>:0: error: unable to load standard library for target 'arm64-apple-ios10.0-simulator'

Merge Script:

 # 1
# Set bash script to exit immediately if any commands fail.
set -e

# 2
# Setup some constants for use later on.
FRAMEWORK_NAME="SDK"
OUTPUT_PATH="${SRCROOT}"

# 3
# If remnants from a previous build exist, delete them.
if [ -d "${SRCROOT}/build" ]; then
rm -rf "${SRCROOT}/build"
fi

# 4
# Build the framework for device and for simulator (using
# all needed architectures).
xcodebuild -target "${FRAMEWORK_NAME}" -configuration Release -arch 
arm64 -arch armv7 -arch armv7s only_active_arch=no defines_module=yes - 
sdk "iphoneos"
xcodebuild -target "${FRAMEWORK_NAME}" -configuration Release -arch 
x86_64 -arch i386 only_active_arch=no defines_module=yes -sdk 
"iphonesimulator"
Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
tp2376
  • 690
  • 1
  • 7
  • 23

12 Answers12

35

For me just restarting Xcode solved it.

mokagio
  • 16,391
  • 3
  • 51
  • 58
MrAn3
  • 1,335
  • 17
  • 23
  • 5
    Same here, something seem to have updated in the background, when I started xcode it asked to install new components, said yes, all worked fine again. – Albert James Teddy May 21 '20 at 13:55
  • Restarting XCode it is! For me this error occured in combination with a package I added through Swift Package Manager. – Dennis Stücken Jan 27 '21 at 22:40
  • After installing Monterey and Xcode 13 on an M1, and downloading https://www.raywenderlich.com/2243-scene-kit-tutorial-getting-started, compiling raised this error. Deleting derrived data, it asked to install new components. Then it worked. – Allen King Oct 26 '21 at 16:12
27

Actually solved this by selecting Generic iOS Device when building instead of a simulator device.

Edit: I should mention, in Xcode 10.

Edit 2: I'll post my universal framework script

set -e

######################
# Options
######################

REVEAL_ARCHIVE_IN_FINDER=true

FRAMEWORK_NAME="${PROJECT_NAME}"

SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework"

DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework"

UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal"

FRAMEWORK="${UNIVERSAL_LIBRARY_DIR}/${FRAMEWORK_NAME}.framework"


######################
# Build Frameworks
######################


xcodebuild -project ${PROJECT_FILE_PATH} -scheme ${PROJECT_NAME} -sdk iphonesimulator -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator 2>&1


xcodebuild -project ${PROJECT_FILE_PATH} -scheme ${PROJECT_NAME} -sdk iphoneos -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos 2>&1


######################
# Create directory for universal
######################

rm -rf "${UNIVERSAL_LIBRARY_DIR}"

mkdir "${UNIVERSAL_LIBRARY_DIR}"

mkdir "${FRAMEWORK}"


######################
# Copy files Framework
######################

cp -r "${DEVICE_LIBRARY_PATH}/." "${FRAMEWORK}"


######################
# Make an universal binary
######################

lipo "${SIMULATOR_LIBRARY_PATH}/${FRAMEWORK_NAME}" "${DEVICE_LIBRARY_PATH}/${FRAMEWORK_NAME}" -create -output "${FRAMEWORK}/${FRAMEWORK_NAME}" | echo

# For Swift framework, Swiftmodule needs to be copied in the universal framework
if [ -d "${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
cp -f ${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
                                                                      fi

                                                                      if [ -d "${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
                                                                      cp -f ${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
                                                                      fi

                                                                      ######################
                                                                      # On Release, copy the result to release directory
                                                                      ######################
                                                                      OUTPUT_DIR="${PROJECT_DIR}/Output/${FRAMEWORK_NAME}-${CONFIGURATION}-iphoneuniversal/"

                                                                      rm -rf "$OUTPUT_DIR"
                                                                      mkdir -p "$OUTPUT_DIR"

                                                                      cp -r "${FRAMEWORK}" "$OUTPUT_DIR"

                                                                      if [ ${REVEAL_ARCHIVE_IN_FINDER} = true ]; then
                                                                      open "${OUTPUT_DIR}/"
                                                                  fi
trusk
  • 1,634
  • 2
  • 18
  • 32
  • 1
    Xcode auto-updated from 9 -> 10 on me and I was getting an ambiguous compile error when implementing my framework. Building my framework with "Generic iOS Device" worked as suggested. – Kilo Loco Oct 18 '18 at 18:18
  • 1
    Building my framework with "Generic iOS Device" compiles, but it doesn't create the simulator archive I need. Anyone has solved this issue? – jaumevn Oct 24 '18 at 13:31
  • I also noticed we have different options: "Any iOS Device" / "Any iOS Simulator Device" / "Any Mac (Mac Catalyst)". and for my case, I am able to build with "Any Mac (Mac Catalyst)" – zuyao88 May 24 '23 at 01:49
9

I got this issue a few days back so what I did was

  • Quit Xcode
  • Delete the derived data folder
  • Started the Xcode and did a clean build

Doing this helped me to resolve the issue and I was able to run the application again

Bug Hunter Zoro
  • 1,743
  • 18
  • 21
8

What fixed the issue in my case was clearing the environment. Apparently when running a script build phase in Xcode, there are some environment variables set which may interfere with the resolution of the Swift standard library. I had this issue while performing a carthage build from an Xcode "Run Script" phase.

Perform a command by clearing the environment with:

env -i <command>

You may want to keep the PATH and DEVELOPER_DIR environment variables though, in particular when you have multiple Xcode versions installed.

so in your case

env -i DEVELOPER_DIR="$DEVELOPER_DIR" PATH="$PATH" xcodebuild ...
Werner Altewischer
  • 10,080
  • 4
  • 53
  • 60
  • This was the solution for me, do you have any Idea why the environment passed to the "running scripts phase" is not the "same" anymore? Why do we need to specify it manually now? I've solved the issue but I still don't know why did it happen though. Is it a consequence of the new build system? (I don't think it is entirely on it). – Felipe Cesar Assis Sep 23 '18 at 17:26
  • 1
    It would require a complete comparison between the environment set by Xcode 9 vs Xcode 10 to determine exactly which environment variable is the culprit. I did not do that. I discovered though that executing the same command in a separate terminal did succeed, which led me to the conclusion above. – Werner Altewischer Sep 24 '18 at 19:59
  • 1
    Could you please help by providing detailed script that I can use for Xcode 9 and Xcode 10? – Dhruv Oct 08 '18 at 06:49
  • Some diffs I've found with env vars passed to running scripts phase. Target was a simulator. `Xcode9 => CURRENT_ARCH=x86_64,arch=x86_64` `Xcode10 => CURRENT_ARCH=undefined_arch,arch=undefined_arch` – demosten Oct 12 '18 at 13:32
  • 1
    The same solution came up in a [Carthage issue on GitHub](https://github.com/Carthage/Carthage/issues/2613), however, using `env -i` is not an option for me, because that also messes up my git server SSH credentials, which I need for `carthage update` to fetch a non-public framework. Calling the script like `env CURRENT_ARCH=x86_64 arch=x86_64 "$SRCROOT"/../my_script.sh` also doesn't help, I still get the same error. – Dávid Pásztor Oct 25 '18 at 10:53
  • Another option could be to spawn a new login shell: you could do this by specifying --login in the shebang line of your script, e.g. #!/bin/bash --login – Werner Altewischer Oct 25 '18 at 11:05
  • 3
    From the [quoted Carthage GitHub issue](https://github.com/Carthage/Carthage/issues/2613#issuecomment-471575964), the problematic env variable seems to be `LLVM_TARGET_TRIPLE_SUFFIX`. Unsetting it solves the issue for me (thank you @DávidPásztor !). – theRealRobG May 03 '19 at 10:35
8

for new versions of Xcode try opening Xcode through Rosetta

Right click on Xcode in applications folder -> Get Info -> set Open with Rosetta to true

enter image description here

Mahmoud Adam
  • 5,772
  • 5
  • 41
  • 62
  • Command CompileSwiftSources emitted errors but did not return a nonzero exit code to indicate failure. Unable to load standard library for target 'arm64-apple-ios10.3' Build was failing getting above issue. It fixed by doing this step application->xcode-> Check Open Using Rosetta -> Clean build and build again. – Ashi Jul 27 '22 at 10:00
  • Aye, this is the one that worked for me, thanks mate. – igneosaur Oct 19 '22 at 09:03
7

I just had this issue occur randomly. There were no build errors in my code. After switching to new simulator & cleaning build folder with no luck, I restarted Xcode (11.5), and the issue self-resolved. Anytime you get weird build failures, restart Xcoode.

pkamb
  • 33,281
  • 23
  • 160
  • 191
Jimmy Dawg
  • 81
  • 1
  • 1
  • 2
    This is a correct answer that someone down-voted. Restarting Xcode results in installation of additional components for iOS/SDK updates, and that removes the problem when the cause is related to updates. – Totoro May 26 '20 at 23:05
2

For me, the following solved the problem:

From the target build Setting

setting Architectures to $(NATIVE_ARCH) and add $(ARCHS_STANDARD) to Valid Architectures.

This might help What's the difference between "Architectures" and "Valid Architectures" in Xcode Build Settings?

M. Adam
  • 108
  • 5
0

Try to add iOS 10 simulator to your xCode. enter image description here

oxigen
  • 6,263
  • 3
  • 28
  • 37
  • 1
    thanks for the tip but it's not that in my case .. I forgot to mention Xcode10 in command line tools that we can find in Xcode->Preferences->Locations Tab ..after i did this it was working fine. – tp2376 Jul 27 '18 at 17:33
  • @tp2376 can you please uncheck this as accepted answer – Boris Y. Oct 24 '18 at 09:35
0

Possibly connected to bad swift version

Try to check your current swift packages with

swiftenv versions

use install or uninstall commands respectively

swiftenv uninstall (install)

To install swiftenv use

brew install kylef/formulae/swiftenv
Igor Kovryzhkin
  • 2,195
  • 1
  • 27
  • 22
0

Thanks for the all answers but seems it's Xcode installation bug ..I dowloaded Xcode again and tested everything works fine in my case.

tp2376
  • 690
  • 1
  • 7
  • 23
0

Resetting all environment variables is not a solution, since that will also unset SSH keys for instance, which will cause cloning to fail in case SSH authentication is used.

However, the only problematic environment variable is LLVM_TARGET_TRIPLE_SUFFIX, so unsetting that solves the problem.

unset LLVM_TARGET_TRIPLE_SUFFIX
carthage update 2>&1
Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
-1

Install latest Xcode 10 GM seed, facing same issue tried many solution but after updating to new Xcode issue resolved. if still issue be there then try this go to File and project setting, set build system to legacy build system, clean and build.

enter image description here

Muhammad Shauket
  • 2,643
  • 19
  • 40