When updating to Xcode 10, iOS static library target fails to build. Way how I am trying to build it is following:
xcodebuild -target TargetName -configuration Release clean build
With Xcode 9 everything runs smoothly, but when Xcode 10 is used for build, I am getting following error (after clean runs smoothly):
note: Using new build system
note: Planning build
note: Constructing build description Build system information error:
unable to attach DB: error: accessing build database
"/Users/uerceg/random-path/build/XCBuildData/build.db": database is
locked Possibly there are two concurrent builds running in the same
filesystem location.
** BUILD FAILED **
** BUILD FAILED **
The following build commands failed: PhaseScriptExecution
MultiPlatform\ Build
/Users/uerceg/random-path/build/Library.build/Release-iphoneos/LibraryTarget.build/Script-9DE7C9021AE68FA5001556E5.sh
(1 failure)
This probably unrelated, but I noticed that new Xcode 10 build system flags duplicated Copy Bundle Resource Info.plist files as errors, so I did make sure that there're no duplicated entries, but probably this error is not related to this fact.
Does anyone have any idea what might be wrong?
Okay, seems like I managed to solve it. I was having /bin/sh script in Build Phases that was trying to build fat static library. In the script, I had OBJROOT path set like this:
OBJROOT="${OBJROOT}"
Seems like Xcode 10 and new build system changed some paths on the way and this line was the source of the issue. It needs to be adjusted to:
OBJROOT="${OBJROOT}/DependentBuilds"
After that, xcodebuild manages to build this target without issues with new build system introduced in Xcode 10.
I didn't get to this solution by myself, big thanks to Matt Gallagher and his post in here: https://github.com/mattgallagher/CwlSignal/issues/24#issuecomment-396931001
As requested by #TMin in comment, here's how my script looks like:
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}/static/${RW_FRAMEWORK_NAME}Sdk.framework"
function build_static_library {
echo "1"
echo "${BUILD_DIR}"
# Will rebuild the static library as specified
# build_static_library sdk
xcrun xcodebuild -project "${PROJECT_FILE_PATH}" \
-target "${TARGET_NAME}" \
-configuration "${CONFIGURATION}" \
-sdk "${1}" \
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]}
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
# 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}"
# 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}"
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}Sdk"
# Ensure that the framework is present in both platform's build directories
cp -a "${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}Sdk" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/static/${RW_FRAMEWORK_NAME}Sdk.framework/Versions/A/${RW_FRAMEWORK_NAME}Sdk"
# Copy the framework to the project directory
ditto "${RW_FRAMEWORK_LOCATION}" "${SRCROOT}/Frameworks/static/${RW_FRAMEWORK_NAME}Sdk.framework"
Problem is in build_static_library method in this line:
OBJROOT="${OBJROOT}" \
Changing that line to:
OBJROOT="${OBJROOT}/DependantBuilds" \
solves the issue for me.
Open XCode File->Project Settings
Build System->Legacy Build System
Configure XCode of version 10.0 project settings can solve the problem.
If you use build script to build submodule's libraries like me.
You also need to disable new build system in your build script explicitly by using -UseModernBuildSystem=NO in your xcodebuild command.
For example:
xcodebuild -configuration "${CONFIGURATION}" -project "${PROJECT_NAME}.xcodeproj" -target "${TARGET_NAME}" -sdk "${OTHER_SDK_TO_BUILD}" ${ACTION} RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" SYMROOT="${SYMROOT}" -UseModernBuildSystem=NO
Deleting the Derived Data worked for me.
See how you can do it: https://programmingwithswift.com/delete-derived-data-xcode/
I have the same issues and try everything from the hints but this error still continues. Sometimes the project is built, next time there is no and error. And the solution that helps me is to edit scheme and switch off Parallelize Build. After that everything works fine.
Use this script it will it is working fine with new build system
# Step 1 search RECURSION and if detected stop "*/
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# Step 2. Build Device and Simulator versions
xcodebuild -target logger ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
xcodebuild -target logger-configuration ${CONFIGURATION} -sdk iphonesimulator -arch i386 -arch x86_64 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 3. Create universal binary file using lipo
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}universal.a" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a"
# Last touch. copy the header files. Just for convenience
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/include" "${UNIVERSAL_OUTPUTFOLDER}/"
fi
before Xcode 10 build system uses single thread, but in Xcode 10 usees new build system with multiple threads, so every time you run your build Xcode run button this script
xcodebuild -target logger ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}".
will call one more time for build so on, that will create RECURSION
Don't forgot to end you Script With (fi) its end of IF condition
Step 1 is to Detect RECURSION and stop them
If you want to keep the XCode 10 default build system but still running your build outside of the IDE (in a CI machine for instance), just replace your -target parameter for the -scheme parameter in your xcodebuild command like:
xcodebuild -scheme SchemeName -configuration Release clean build
Thanks to this post from 2015 that talks about a very similar problem and it gave me the hint to solve this problem. As the same author says,
I would hazard a guess, that xcodebuild without a scheme goes
wrongly through the "modern build system", giving the mentioned error
Adding a Clean derived data step in my build scripts (before an Xcode build) seems to fix the problem for me.
Not sure if it's related, but my project uses Realm (installed with CocoaPods). This is the GitHub issue that inspired the "fix" -> https://github.com/realm/realm-cocoa/issues/5812.
I encountered this issue when running swift run <your_proj>.
A quick fix can be achieved by deleting the build.db file, along with its sibling files and directories. This may seem trifle, but it worked for me.
I am reposting this because a moderator saw it fit to delete my previous answer.
I encountered the same issues when I upgraded by builds to New Build System because of xcframeworks requirements.
Error: ".....Build/Intermediates.noindex/XCBuildData/build.db": database is locked Possibly there are two concurrent builds running in the same filesystem location."
The build was previously working fine when triggered with xcodebuild( )
None of the above/approved answered worked for me.
What worked for me was a switch from xcodebuild( ) to build_app( ) in my Fastlane script.
Hope this answer helps someone in the future.
For me, I just cleaned my project.
Restarted the IDE & rebuilt the project & it worked like a charm.
It could be because you have in your podfile an incompatible version to make sure open the runner.xcodeproj with xcode and see the version then go and see podfile to make sure it is the same and uncomented if not make them the same.
hope this is helpful.
I try to build static framework.
So I run following commands:
for device
xcodebuild
-project MyAppLib.xcodeproj
-sdk iphoneos
-target $PRODUCT_FRAMEWORK
-configuration Release clean build
for simulator
xcodebuild
-project MyAppLib.xcodeproj
-sdk iphonesimulator
-target $PRODUCT_FRAMEWORK
-configuration Release clean build
However when I try to run lipo:
lipo -create build/Release-iphonesimulator/MyAppLib.framework/MyAppLib
build/Release-iphoneos/MyAppLib.framework/MyAppLib
-output MyAppLib.framework
I get an error:
fatal error:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo:
build/Release-iphonesimulator/MyAppLib.framework/MyAppLib and
build/Release-iphoneos/MyAppLib.framework/MyAppLib have the same
architectures (i386) and can't be in the same fat output file
From Xcode I success to build it but from CLI both have the same structure.
$ file MyAppLib.framework gives me:
MyAppLib.framework: Mach-O universal binary with 4 architectures: [i386: current ar archive] [arm_v7: current ar archive] [x86_64: current ar archive] [arm64]
MyAppLib.framework (for architecture i386): current ar archive
MyAppLib.framework (for architecture armv7): current ar archive
MyAppLib.framework (for architecture x86_64): current ar archive
MyAppLib.framework (for architecture arm64): current ar archive
If I try to run only for one platform, the build is succeeded but I get strange framework that I cannot even explore it:
Edit:
Multiplatform script:
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
xcrun xcodebuild -project "${PROJECT_FILE_PATH}" \
-target "${TARGET_NAME}" \
-configuration "${CONFIGURATION}" \
-sdk "${1}" \
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]}
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
# 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}"
# 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}"
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"
Solution:
You do not have a problem. The MyAppLib.framework that appears after building your project is your static library, containing slices for all required architectures.
No need to use lipo after building your project.
Issue:
Your build script "automatically" builds your target twice, once for devices and once for simulators. Afterwards it merges both build artefacts to one fat lib (make_fat_library) using lipo.
Afterwards it copies the result around to:
#Ensure that the framework is present in both platform's build directories
As a result, you have a fat lib framework in both build directories.
Now you are trying to merge those two (already merged) fat libs. As both contain the same slices you get the error.
I can create Framework in XCode using "Aggregate target". Also it's possible to create "Cocoa Touch Framework" in XCode 7.
What is difference between them?
What way is preferable in new project?
I prefer to make Cocoatouch framework.
And finally, run the script to make it universal framework.
You don't need to make it to the aggregate.
FYI, here is the script I'm using now.
I found this script from the web. (I cannot remember the source)
set -e
set +u
# Avoid recursively calling this script.
if [[ $SF_MASTER_SCRIPT_RUNNING ]]
then
exit 0
fi
set -u
export SF_MASTER_SCRIPT_RUNNING=1
# Constants
SF_TARGET_NAME=${PROJECT_NAME}
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# Take build target
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]
then
SF_SDK_PLATFORM=${BASH_REMATCH[1]}
else
echo "Could not find platform name from SDK_NAME: $SDK_NAME"
exit 1
fi
if [[ "$SF_SDK_PLATFORM" = "iphoneos" ]]
then
echo "Please choose iPhone simulator as the build target."
exit 0
fi
IPHONE_DEVICE_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos
# Build the other (non-simulator) platform
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}" -configuration "${CONFIGURATION}" -sdk iphoneos BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}/arm64" SYMROOT="${SYMROOT}" ARCHS='arm64' VALID_ARCHS='arm64' $ACTION
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}" -configuration "${CONFIGURATION}" -sdk iphoneos BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}/armv7" SYMROOT="${SYMROOT}" ARCHS='armv7 armv7s' VALID_ARCHS='armv7 armv7s' $ACTION
# Copy the framework structure to the universal folder (clean it first)
rm -rf "${UNIVERSAL_OUTPUTFOLDER}"
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework"
# Smash them together to combine all architectures
lipo -create "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/arm64/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/armv7/${PROJECT_NAME}.framework/${PROJECT_NAME}" -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}"
Go to project settings -> build phases and then click the plus button to add new run script.
If you need to support iOS < 8.o then you can't use "Cocoa Touch Framework"
I'm building my own framework by following the guide on site
Create a framework for iOS - RayWenderlich
It works well, but when I integrate the framework on test project, it catches error as "undefined symbol for architecture arm64". When I check the supported architectures by the command
<myframework>.framework xcrun lipo -info <myframework>
it misses 2 architectures armv7s and x86_64
Here is my run script on Aggregate target
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
xcrun xcodebuild -project "${PROJECT_FILE_PATH}" \
-target "${TARGET_NAME}" \
-configuration "${CONFIGURATION}" \
-sdk "${1}" \
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]}
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
# 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}"
# 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}"
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"
I suppose the build error when integrating framework to test project causes by the missing architecture when building framework
Solved, in my case: in the main target (RWUIControls, if you refer to Ray W. post) I added manually the armv7s architecture.
See screenshot below:
if I run the command from the terminal:
xcrun lipo -info RWUIControls
inside the framework folder now I get:
Architectures in the fat file: RWUIControls are: armv7 armv7s i386 x86_64 arm64
It's easy only change the iOS Development Target in the project Info.
In my case I had selected iOS 13 then I changed it to iOS 10 and now I have those Archs -> armv7 i386 x86_64 arm64.
These are the Architectures depending on the iOS device.
armv64: iPhoneX, iPhone 5s-8, iPad Air — iPad Pro
armv7 : iPhone3Gs-5c, iPad WIFI(4th gen)
armv6 : iPhone — iPhone3G
the above if for real devices
i386 : 32-bit simulator
x86_64 : 64-bit simulator
I have a bash script that builds my iOS static library for both ARM and i386 architectures. I am then using lipo to combine the binaries into a single "combined" library so that it can be linked to in the simulator as well as on a device. For some reason when I attempt to link against the resulting fat library I still get linker errors complaining that symbols are not found for i386 when debugging. I'm wondering if I am not building the simulator or iphoneos libraries correctly before using lipo. Can someone help me out?
Here is my bash script:
if [ $1 == "clean" ]
then
echo -e "Perform Clean\n"
if [ -d build ]
then
rm -r build
exit
fi
else
echo -e "Begin combined build process.\n"
XCODEBUILD_PATH=/Applications/Xcode.app/Contents/Developer/usr/bin
XCODEBUILD=$XCODEBUILD_PATH/xcodebuild
echo -e "xcode build executable path: $XCODEBUILD\nBuiding i386 static library.\n"
$XCODEBUILD -project MyLibrary.xcodeproj -target "MyLibrary" -sdk "iphonesimulator" -configuration "Release" clean build
echo -e "Buiding ARM static library.\n"
$XCODEBUILD -project MyLibrary.xcodeproj -target "MyLibrary" -sdk "iphoneos" -configuration "Release" clean build
echo -e "Combine ARM and i386 libs.\nOutput: build/combined/libMyLibrary.a\n"
[ -d build/Release-combined ] || mkdir build/Release-combined
lipo -create -output "build/Release-combined/libMyLibrary.a" "build/Release-iphoneos/libMyLibrary.a" "build/Release-iphonesimulator/libMyLibrary.a"
echo -e "Done!\n"
fi
exit
When I add link against the resulting lib "build/Release-combined/libMyLibrary.a". I get linking issues. Am I doing something wrong?
Thanks!
Well there are 2 ways to make gcc/clang build a different arch.
you can pass the -m32 or -m64 flag...
but it is more explicit to use the -arch x86_64 -arch i386 flags which in apple clang and apple gcc can be passed at the same time.