创建单个胖文件时面对lipo错误

时间:2011-04-28 04:42:18

标签: iphone cocoa-touch ios static-libraries

我正在尝试创建一个.a文件,其中包含3个不同的.a文件,以便我只能共享一个.a文件。这是我正在使用的命令

lipo -create -output ./libOutput.a ./libInput1.lib ./libInput2.lib ./libInput3.lib

但我得到了这个口号错误:

  

./ libInput1.lib和./libInput2.lib   拥有相同的架构(i386)和   不能在同一个胖输出文件中

知道怎么摆脱这个吗?

5 个答案:

答案 0 :(得分:4)

我刚刚收到了同样的错误消息,这是因为我将我的架构设置为“其他”并且已经输入了arm6。为了解决这个问题,我只是将我的架构设置更改为默认值之一,在我的情况下,我选择了Standard(arm6 arm7)。可以在项目构建设置中找到“架构”设置。

答案 1 :(得分:3)

对我有用的解决方法(因为我无法弄清楚构建过程的哪个部分正在为编译创建额外的体系结构目标):只需从两个.a库中删除该体系结构。

首先,您可以使用简单的文件命令列出架构:

$ file libwhatever.a
libwhatever.a: Mach-O universal binary with 4 architectures
libwhatever.a (for architecture armv7): current ar archive random library
libwhatever.a (for architecture armv7s): current ar archive random library
libwhatever.a (for architecture arm64): current ar archive random library
libwhatever.a (for architecture i386): current ar archive random library

$ file libfoo.a
libfoo.a: Mach-O universal binary with 2 architectures
libfoo.a (for architecture i386): current ar archive random library
libfoo.a (for architecture x86_64): current ar archive random library

然后,这个解决方法就是从第一个 libwhatever.a 中移除i386拱门(无论如何,这应该只是针对arm * arch)。

lipo -remove i386 libwhatever.a -output /tmp/libwhatever.a
mv /tmp/libwhatever.a libwhatever.a

然后您可以创建/合并.a文件而不会发出任何警告。

答案 2 :(得分:2)

所以这是我第二次来到这里。答案并没有解决我的问题。我发现这实际上是Xcode中的一个错误。两次发生的事情是我来找到这个答案,这不是我的问题然后我在弄乱了几个小时试图弄清楚发生了什么,接下来我知道Xcode崩溃了。再次打开Xcode,魔术问题就消失了。

所以我正在添加我的答案,以帮助我记住下一次。

答案 3 :(得分:2)

好的,我明白了。这是我的(整个)版本的运行脚本

# Taken from Ray Wenderlich tutorial: http://www.raywenderlich.com/65964/create-a-framework-for-ios

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"

OUTPUT_LOCATION="${HOME}/Desktop"
if [ ! -w ${OUTPUT_LOCATION} ] ; then OUTPUT_LOCATION="${XCS_OUTPUT_DIR}" ; fi
if [ ! -w ${OUTPUT_LOCATION} ] ; then OUTPUT_LOCATION="/tmp" ; fi
if [ ! -w ${OUTPUT_LOCATION} ] ; then echo "Couldn't find anywhere to write! Dying."; exit 1 ; fi

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

echo "RW_SDK_PLATFORM is ${RW_SDK_PLATFORM}"

# 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

echo "RW_SDK_VERSION is ${RW_SDK_VERSION}"

# 3 - Determine the other platform
if [ "$RW_SDK_PLATFORM" == "iphoneos" ]; then
RW_OTHER_PLATFORM=iphonesimulator
else
RW_OTHER_PLATFORM=iphoneos
fi

echo "RW_OTHER_PLATFORM is ${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

echo "BUILT_PRODUCTS_DIR is ${BUILT_PRODUCTS_DIR}"
echo "RW_OTHER_BUILT_PRODUCTS_DIR is ${RW_OTHER_BUILT_PRODUCTS_DIR}"

# remove alias and copy, if it's archive
UNINSTALLED_PRODUCTS_DIRECTORY="${BUILT_PRODUCTS_DIR}/../../IntermediateBuildFilesPath/UninstalledProducts"

if [ -d "$UNINSTALLED_PRODUCTS_DIRECTORY" ]; then
    echo "Looks like we're archiving, fixing aliases..."
    rm "${BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}"
    cp "${UNINSTALLED_PRODUCTS_DIRECTORY}/${RW_INPUT_STATIC_LIB}" "${BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}"
fi

# Build the other platform.
build_static_library "${RW_OTHER_PLATFORM}${RW_SDK_VERSION}"

if [ -d "$UNINSTALLED_PRODUCTS_DIRECTORY" ]; then
    echo "Looks like we're archiving, fixing aliases..."
    rm "${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}"
    cp "${UNINSTALLED_PRODUCTS_DIRECTORY}/${RW_INPUT_STATIC_LIB}" "${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}"
fi

# 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
ditto "${RW_FRAMEWORK_LOCATION}" "${OUTPUT_LOCATION}/${RW_FRAMEWORK_NAME}.framework"

# Copy the resources bundle
ditto "${BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.bundle" \
"${OUTPUT_LOCATION}/${RW_FRAMEWORK_NAME}.bundle"

echo "DONE. ***** FINAL FRAMEWORK AND BUNDLE WERE COPIED HERE: ${OUTPUT_LOCATION} *****"

答案 4 :(得分:0)

转到目标YourLibUniversal / Build Phases / Run script

然后查看脚本是否提到了SIMULATOR_DIR_32和SIMULATOR_DIR_64 如果是,请删除这些引用,只需设置一个参考SIMULATOR_DIR

我有:

SIMULATOR_DIR_32=${SYMROOT}/${CONFIGURATION}-iphonesimulator-i386
SIMULATOR_DIR_64=${SYMROOT}/${CONFIGURATION}-iphonesimulator-x86_64
...
lipo -create "${DEVICE_DIR}/lib${LIB_NAME}.a" "${SIMULATOR_DIR_32}/lib${LIB_NAME}.a" "${SIMULATOR_DIR_64}/lib${LIB_NAME}.a" -output "${INSTALL_DIR}/lib${LIB_NAME}Universal.a"

我改为:

SIMULATOR_DIR=${SYMROOT}/${CONFIGURATION}-iphonesimulator-x86_64
...
lipo -create "${DEVICE_DIR}/lib${LIB_NAME}.a" "${SIMULATOR_DIR}/lib${LIB_NAME}.a" -output "${INSTALL_DIR}/lib${LIB_NAME}Universal.a"
相关问题