如何将 libxslt 包含在我的 iPhone 应用程序中?

发布于 2024-09-18 00:39:37 字数 144 浏览 4 评论 0原文

我听说包含 libxslt.dylib 是您的应用程序被拒绝的理由。我不知道这有多准确。

尽管如此,我想包含最新版本的 libxslt。我想对 libxml2 以及将来的其他库做同样的事情。

在我的应用程序中包含这样的代码库的正确方法是什么?

I've heard that including libxslt.dylib is grounds for getting your app rejected. I don't know how accurate that is.

Nevertheless, I would like to include the latest version of libxslt. I'd like to do the same thing with libxml2, as well as other libraries in the future.

What is the correct way to include a code library like this in my app?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

可爱暴击 2024-09-25 00:39:37

我的应用程序被拒绝,并显示来自 Apple 的以下消息。


XYZ 应用程序无法发布到 App Store,因为它使用私有或未记录的 API:

私有符号引用
xslt应用样式表
xsltCleanupGlobals
xslt免费样式表
xslt初始化
xsltParseStylesheetFile
xsltSaveResultToString

如您所知,正如 iPhone 开发者计划许可协议第 3.3.1 节中所述,不允许使用非公共 API。在应用程序审核团队审核您的应用程序之前,请解决此问题并将新的二进制文件上传到 iTunes Connect。


据我了解,libxslt 和 libxml2 库实际上存在于设备上,并且可以通过 Xcode 中的下拉菜单使用。我动态链接这两个库,我的应用程序在设备上运行得很好。因此,库必须位于设备上。为什么我需要从头开始构建这些库作为静态库并增加我的应用程序的大小?

除了不使用 xml 和 xslt 之外,我找不到任何明确的方法来解决此问题。这根本没有意义!

Hilton,您是否成功向 iTunes 提交了使用 xslt 的应用程序?

My app was rejected with the following message from Apple.


XYZ app cannot be posted to the App Store because it is using private or undocumented APIs:

Private Symbol References
xsltApplyStylesheet
xsltCleanupGlobals
xsltFreeStylesheet
xsltInit
xsltParseStylesheetFile
xsltSaveResultToString

As you know, as outlined in the iPhone Developer Program License Agreement section 3.3.1, the use of non-public APIs is not permitted. Before your application can be reviewed by the App Review Team, please resolve this issue and upload a new binary to iTunes Connect.


It was my understanding that the libxslt and libxml2 libraries were in fact present on the device and are available via the pull down menu in Xcode. I dynamically link link with these two libraries and my app works beautifully on the device. Hence, the libraries must be on the device. Why would I need to build these libraries from scratch as static libraries and increase the size of my app?

I can't find any clear way to work around this, aside from not using xml and xslt. That makes no sense at all!

Hilton, have you succeeded in submitting an app to iTunes that uses xslt?

七度光 2024-09-25 00:39:37

我终于在 Xcode 中构建了 libxslt,链接到我的应用程序,并逃避应用程序商店拒绝机器人。

基本上,您必须静态构建 libxslt 并更改符号名称,以便它们与 Apple 寻找的符号名称不匹配。所有符号 xsltFoo() 必须更改为 zsltFoo()。此外,库本身的名称必须从 libxslt.a 更改为 libzslt.a

以下是如何通过 10 个简单步骤完成此操作:)

  1. 创建一个 libxslt 子目录并将 libxslt-1.1.26.tar.gz 放入其中。
  2. 右键单击目标-> YourApp 并选择添加 ->新建阶段 ->新的运行脚本构建阶段
  3. 复制下面的构建脚本
  4. 将构建阶段从“运行脚本”重命名为“构建 libxslt”,并将其放在列表中的第一位
  5. 构建您的项目,这将导致配置 libxslt并在 libxslt/dist 中构建并安装,
  6. 右键单击 Frameworks 并选择 Add ->现有文件...然后选择libxslt/dist/lib/libzslt.a
  7. 转到Project ->编辑项目设置 -> 在“搜索路径”下构建
  8. ,编辑“标题搜索路径”并添加 libxslt/dist/include
  9. #include 添加到您的代码中,通常需要
  10. 使用zsltFoo 而不是 xsltFoo

以下是步骤 #3 中引用的 libxslt 构建脚本:

#!/bin/sh

# Setup
LIBXSLT_VERSION="1.1.26"
LIBXSLT_SHA1_CHECKSUM="69f74df8228b504a87e2b257c2d5238281c65154"
GCC_VERSION="4.2.1"
ARCH="arm-apple-darwin10"

# Bail on any error
set -e

# Function that patches a file using sed(1).
# First argument is filename, subsequent arguments are passed to sed(1).
sed_patch_file()
{
    FILE="${1}"
    shift
    sed ${1+"$@"} < "${FILE}" > "${FILE}".new
    if ! diff -q "${FILE}" "${FILE}".new >/dev/null; then
        cat "${FILE}".new > "${FILE}"
    fi
    rm "${FILE}".new
}

# Function that displays the command and then executes it
show_cmd()
{
    echo ${1+"$@"}
    ${1+"$@"}
}

# Dump environment variables
#echo '***************************************************'
#env | sort
#echo '***************************************************'

# Files
SRCBALL="${SOURCE_ROOT}/libxslt/libxslt-${LIBXSLT_VERSION}.tar.gz"
SRCDIR="${SOURCE_ROOT}/libxslt/libxslt-${LIBXSLT_VERSION}"
DISTDIR="${SOURCE_ROOT}/libxslt/dist"

# Verify source is installed
if ! [ -f "${SRCBALL}" ]; then
    echo "ERROR: please download and install ${SRCBALL}" 2>&1
    echo "The SHA1 checksum should be: ${LIBXSLT_SHA1_CHECKSUM}" 2>&1
    exit 1
fi

# Unpack the archive if necessary
if ! [ -e "${SRCDIR}" ]; then

    # Unpack archive
    echo "*** Unpacking archive ${SRCBALL}"
    tar zxf "${SRCBALL}" -C libxslt

    # Rename all symbols xsltFoobar -> zsltFoobar to avoid broken app store link analyzer
    echo "*** Changing symbol names"
    find libxslt/libxslt-"${LIBXSLT_VERSION}" -name '*.[ch]' -print | while read FILE; do
        sed_patch_file "${FILE}" -E 's%([^[:alnum:]_/"]|^)xslt([A-Z])%\1zslt\2%g'
    done

    # Disable build of xsltproc which fails to link
    sed_patch_file libxslt/libxslt-"${LIBXSLT_VERSION}"/Makefile.in -E '/^[[:space:]]xsltproc \\$/d'
fi

# Build and install
if ! [ -e "${DISTDIR}" ]; then

    # Set up autoconf environment variables
    export CPP="${PLATFORM_DEVELOPER_BIN_DIR}/${ARCH}-gcc-${GCC_VERSION} -E"
    export  CC="${PLATFORM_DEVELOPER_BIN_DIR}/${ARCH}-gcc-${GCC_VERSION}"
    export CXX="${PLATFORM_DEVELOPER_BIN_DIR}/${ARCH}-g++-${GCC_VERSION}"
    export CPPFLAGS="-I${SDKROOT}/usr/lib/gcc/${ARCH}/${GCC_VERSION}/include -I${SDKROOT}/usr/include"
    export LDFLAGS="--sysroot=${SDKROOT}"
    export CFLAGS="-Os -pipe ${CPPFLAGS} ${LDFLAGS}"
    export CXXFLAGS="${CFLAGS}"
    export ARCH

    # Configure libxslt
    echo "*** Configuring libxslt-${LIBXSLT_VERSION}"
    ( cd "${SRCDIR}" && show_cmd ./configure \
      --prefix="${DISTDIR}" \
      --build=i386-apple-darwin10 \
      --host="${ARCH}" \
      --enable-static \
      --disable-shared \
      --with-libxml-include-prefix="${SDKROOT}"/usr/include \
      --with-libxml-libs-prefix="${SDKROOT}"/usr/lib \
      --without-python )

    # Build it
    echo "*** Building libxslt-${LIBXSLT_VERSION}"
    ( cd "${SRCDIR}" && show_cmd make )

    # Install it
    echo "*** Installing libxslt-${LIBXSLT_VERSION}"
    ( cd "${SRCDIR}" && show_cmd make install )

    # Change library name to avoid dynamic linking to the iPhone's shared libxslt library
    ln libxslt/dist/lib/lib{x,z}slt.a
fi

I finally got libxslt to build in Xcode, link to my app, and evade the app store rejectionbot.

Basically you have to build libxslt statically and change the symbol names so they don't match the ones that Apple looks for. All symbols xsltFoo() must be changed to zsltFoo(). Also the name of the library itself must be changed from libxslt.a to libzslt.a.

Here's a how to do it in 10 easy steps :)

  1. Create a libxslt subdirectory and put libxslt-1.1.26.tar.gz into it.
  2. Right click on Target -> YourApp and select Add -> New Build Phase -> New Run Script Build Phase
  3. Copy the build script below
  4. Rename the the build phase from "Run Script" to "Build libxslt" and make it first in the list
  5. Build your project, which will cause libxslt to be configured and built and installed in libxslt/dist
  6. Right click on Frameworks and select Add -> Existing Files... and then select libxslt/dist/lib/libzslt.a
  7. Go to Project -> Edit Project Settings -> Build
  8. Under Search Paths, edit Header Search Paths and add libxslt/dist/include
  9. Add #include <libxslt/whatever.h> to your code as needed normally
  10. Use zsltFoo instead of xsltFoo everywhere in your code

Here is the libxslt build script referenced in step #3:

#!/bin/sh

# Setup
LIBXSLT_VERSION="1.1.26"
LIBXSLT_SHA1_CHECKSUM="69f74df8228b504a87e2b257c2d5238281c65154"
GCC_VERSION="4.2.1"
ARCH="arm-apple-darwin10"

# Bail on any error
set -e

# Function that patches a file using sed(1).
# First argument is filename, subsequent arguments are passed to sed(1).
sed_patch_file()
{
    FILE="${1}"
    shift
    sed ${1+"$@"} < "${FILE}" > "${FILE}".new
    if ! diff -q "${FILE}" "${FILE}".new >/dev/null; then
        cat "${FILE}".new > "${FILE}"
    fi
    rm "${FILE}".new
}

# Function that displays the command and then executes it
show_cmd()
{
    echo ${1+"$@"}
    ${1+"$@"}
}

# Dump environment variables
#echo '***************************************************'
#env | sort
#echo '***************************************************'

# Files
SRCBALL="${SOURCE_ROOT}/libxslt/libxslt-${LIBXSLT_VERSION}.tar.gz"
SRCDIR="${SOURCE_ROOT}/libxslt/libxslt-${LIBXSLT_VERSION}"
DISTDIR="${SOURCE_ROOT}/libxslt/dist"

# Verify source is installed
if ! [ -f "${SRCBALL}" ]; then
    echo "ERROR: please download and install ${SRCBALL}" 2>&1
    echo "The SHA1 checksum should be: ${LIBXSLT_SHA1_CHECKSUM}" 2>&1
    exit 1
fi

# Unpack the archive if necessary
if ! [ -e "${SRCDIR}" ]; then

    # Unpack archive
    echo "*** Unpacking archive ${SRCBALL}"
    tar zxf "${SRCBALL}" -C libxslt

    # Rename all symbols xsltFoobar -> zsltFoobar to avoid broken app store link analyzer
    echo "*** Changing symbol names"
    find libxslt/libxslt-"${LIBXSLT_VERSION}" -name '*.[ch]' -print | while read FILE; do
        sed_patch_file "${FILE}" -E 's%([^[:alnum:]_/"]|^)xslt([A-Z])%\1zslt\2%g'
    done

    # Disable build of xsltproc which fails to link
    sed_patch_file libxslt/libxslt-"${LIBXSLT_VERSION}"/Makefile.in -E '/^[[:space:]]xsltproc \\$/d'
fi

# Build and install
if ! [ -e "${DISTDIR}" ]; then

    # Set up autoconf environment variables
    export CPP="${PLATFORM_DEVELOPER_BIN_DIR}/${ARCH}-gcc-${GCC_VERSION} -E"
    export  CC="${PLATFORM_DEVELOPER_BIN_DIR}/${ARCH}-gcc-${GCC_VERSION}"
    export CXX="${PLATFORM_DEVELOPER_BIN_DIR}/${ARCH}-g++-${GCC_VERSION}"
    export CPPFLAGS="-I${SDKROOT}/usr/lib/gcc/${ARCH}/${GCC_VERSION}/include -I${SDKROOT}/usr/include"
    export LDFLAGS="--sysroot=${SDKROOT}"
    export CFLAGS="-Os -pipe ${CPPFLAGS} ${LDFLAGS}"
    export CXXFLAGS="${CFLAGS}"
    export ARCH

    # Configure libxslt
    echo "*** Configuring libxslt-${LIBXSLT_VERSION}"
    ( cd "${SRCDIR}" && show_cmd ./configure \
      --prefix="${DISTDIR}" \
      --build=i386-apple-darwin10 \
      --host="${ARCH}" \
      --enable-static \
      --disable-shared \
      --with-libxml-include-prefix="${SDKROOT}"/usr/include \
      --with-libxml-libs-prefix="${SDKROOT}"/usr/lib \
      --without-python )

    # Build it
    echo "*** Building libxslt-${LIBXSLT_VERSION}"
    ( cd "${SRCDIR}" && show_cmd make )

    # Install it
    echo "*** Installing libxslt-${LIBXSLT_VERSION}"
    ( cd "${SRCDIR}" && show_cmd make install )

    # Change library name to avoid dynamic linking to the iPhone's shared libxslt library
    ln libxslt/dist/lib/lib{x,z}slt.a
fi
秋叶绚丽 2024-09-25 00:39:37

嘿 Hilton,您是否可以让我们知道您如何设法将 LIBXSLT 库静态链接到您的应用程序中?

我和其他一些人遇到了完全相同的问题,但至少目前,我不知道如何将动态库变成静态库。

谢谢。

编辑:查看这个 iPhone 中的 XSLT 版本

我的应用程序被拒绝因为使用 LibXSLT 所以我手动添加源代码并这样做。我的应用程序几天前获得批准。

Hey Hilton, any chance you could let us know how you managed to statically link the LIBXSLT library into your app please?

I'm having exactly the same issue as quite a few others but at the moment at least, I have no idea how to go about turning the dynamic library into a static one.

Thanks.

EDIT: Check out this Version of XSLT in iPhone

My app was rejected for using LibXSLT so instead I manually added the source code and did it that way. My app was approved a few days ago.

纵性 2024-09-25 00:39:37

您只能动态链接到设备上已存在的库。

如果您想链接到设备上不存在的外部库,您必须自己将其编译为静态库并链接它。

You can only dynamically link to libraries that are already present on the device.

If you want to link to an external library that is not present on the device, you will have to compile it yourself to a static library and link that instead.

甜味拾荒者 2024-09-25 00:39:37

根据Archie的回答,这个脚本(使用XCode 5命令行工具)生成一个适合包含在项目中的多架构libzslt,与iOS 6和iOS 7项目兼容(尽管我没有包含iOS 7 64位)。

此解决方案假设 libxslt-1.1.28 已解压并位于与脚本相同的目录中。

该脚本创建一个目录依赖项,其中包含头文件和 lib 文件。您可以通过调整标头和链接器搜索路径将它们包含在 Xcode 项目中。



    #!/bin/sh
    # build.sh

    GLOBAL_OUTDIR="`pwd`/dependencies"
    LOCAL_OUTDIR="outdir"
    XSLT_LIB="`pwd`/libxslt-1.1.28"

    IOS_BASE_SDK="7.0"
    IOS_DEPLOY_TGT="6.0"

    sed_patch_file()
    {
        FILE="${1}"
        shift
        sed ${1+"$@"}  "${FILE}".new
        if ! diff -q "${FILE}" "${FILE}".new >/dev/null; then
            cat "${FILE}".new > "${FILE}"
        fi
        rm "${FILE}".new
    }

    patch_libxslt() {
        export LIBXSLT_VERSION=1.1.28
        echo "*** Changing symbol names"
        find libxslt-"${LIBXSLT_VERSION}" -name '*.[ch]' -print | while read FILE; do
                sed_patch_file "${FILE}" -E 's%([^[:alnum:]_/"]|^)xslt([A-Z])%\1zslt\2%g'
        done

            # Disable build of xsltproc which fails to link
        sed_patch_file libxslt-"${LIBXSLT_VERSION}"/Makefile.in -E '/^[[:space:]]xsltproc \\$/d'
    }

    setenv_all()
    {
        unset LIBRARIES
        export LIBRARIES=${SDKROOT}/usr/lib
        echo "*** LIBRARIES: ${LIBRARIES}"

        # Add internal libs
        export LDFLAGS="--sysroot=${SDKROOT} $LDFLAGS -L${LIBRARIES}"
        export CFLAGS="--sysroot=${SDKROOT} $CFLAGS -I${SDKROOT}/usr/lib/gcc/${ARCH}/${GCC_VERSION}/include -I${SDKROOT}/usr/include -arch ${ARCH} -Os -pipe ${CPPFLAGS}"

        export CXX="$PLATFORM_BIN_DIR/g++"
        export CC="$PLATFORM_BIN_DIR/gcc"

        export LD=$TOOLROOT/ld
        export AR=$TOOLROOT/ar
        export AS=$TOOLROOT/as
        export NM=$TOOLROOT/nm
        export RANLIB=$TOOLROOT/ranlib
        export CPPFLAGS=$CFLAGS
        export CXXFLAGS=$CFLAGS

        export CXXFLAGS="${CFLAGS}"
    }

    setenv_arm7()
    {
        unset LN DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM CXXCPP RANLIB LDFLAGS CPPFLAGS CXXFLAGS DYLD_LIBRARY_PATH ARCH PLATFORM_BIN_DIR TOOLROOT DISTDIR

        export ARCH=armv7
        export DEVROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
        export SDKROOT=$DEVROOT/SDKs/iPhoneOS$IOS_BASE_SDK.sdk
        export PLATFORM_BIN_DIR=/Applications/Xcode.app/Contents/Developer/usr/bin
        export TOOLROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin    

        export DYLD_LIBRARY_PATH="$SDKROOT/usr/lib"

        export CFLAGS="-arch armv7 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT -I$SDKROOT/usr/include/"

        setenv_all
    }

    setenv_arm7s()
    {
        unset LN DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM CXXCPP RANLIB LDFLAGS CPPFLAGS CXXFLAGS DYLD_LIBRARY_PATH ARCH PLATFORM_BIN_DIR TOOLROOT DISTDIR

        export ARCH=armv7s
        export DEVROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
        export SDKROOT=$DEVROOT/SDKs/iPhoneOS$IOS_BASE_SDK.sdk
        export PLATFORM_BIN_DIR=/Applications/Xcode.app/Contents/Developer/usr/bin
        export TOOLROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin    

        export DYLD_LIBRARY_PATH="$SDKROOT/usr/lib"

        export CFLAGS="-arch armv7s -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT -I$SDKROOT/usr/include/"

        setenv_all
    }

    setenv_i386()
    {
        unset LN DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM CXXCPP RANLIB LDFLAGS CPPFLAGS CXXFLAGS DYLD_LIBRARY_PATH ARCH PLATFORM_BIN_DIR TOOLROOT DISTDIR

        export ARCH=i386
        export DEVROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer
        export SDKROOT=$DEVROOT/SDKs/iPhoneSimulator$IOS_BASE_SDK.sdk
        export PLATFORM_BIN_DIR=$DEVROOT/usr/bin
        export TOOLROOT=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

        export CFLAGS="-arch i386 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT"

        setenv_all
    }

    create_outdir_lipo()
    {
        for lib_i386 in `find $LOCAL_OUTDIR/i386 -name "lib*\.a"`; do
            lib_arm7=`echo $lib_i386 | sed "s/i386/arm7/g"`
            lib_arm7s=`echo $lib_i386 | sed "s/i386/arm7s/g"`
            lib=`echo $lib_i386 | sed "s/i386\///g"`
            mkdir -p $(dirname $lib)
            cmd="xcrun -sdk iphoneos lipo -arch armv7 $lib_arm7 -arch i386 $lib_i386 -arch armv7s $lib_arm7s -create -output $lib"
            echo $cmd
            $cmd
        done
    }

    merge_libfiles()
    {
        DIR=$1
        LIBNAME=$2

        cd $DIR
        for i in `find . -name "lib*.a"`; do
            $AR -x $i
        done
        $AR -r $LIBNAME *.o
        rm -rf *.o __*
        cd -
    }

    #######################
    # libxslt
    #######################

    patch_libxslt

    cd $XSLT_LIB
    rm -rf $LOCAL_OUTDIR
    mkdir -p $LOCAL_OUTDIR/arm7 $LOCAL_OUTDIR/i386

    make clean 2> /dev/null
    setenv_i386

    export DISTDIR=`pwd`/$LOCAL_OUTDIR/i386

    ./configure --prefix="${DISTDIR}" \
    --enable-static \
    --disable-shared \
    --with-libxml-include-prefix="${SDKROOT}"/usr/include \
    --with-libxml-libs-prefix="${SDKROOT}"/usr/lib \
    --without-crypto \
    --without-python || exit
    make "CC=$CC" "CFLAGS=$CFLAGS" "AR=$AR"
    make install

    ln $LOCAL_OUTDIR/i386/lib/lib{x,z}slt.a 

    # find ./ -iname *.a | grep -v $LOCAL_OUTDIR | xargs -L 1 -I '{}' cp '{}' $LOCAL_OUTDIR/i386
    # cp -vf lib*.a $LOCAL_OUTDIR/i386

    make clean 2> /dev/null
    setenv_arm7

    export DISTDIR=`pwd`/$LOCAL_OUTDIR/arm7

    ./configure --prefix="${DISTDIR}" \
    --host=armv7-apple-darwin12.5.0 \
    --enable-static \
    --disable-shared \
    --with-libxml-include-prefix="${SDKROOT}"/usr/include \
    --with-libxml-libs-prefix="${SDKROOT}"/usr/lib \
    --without-crypto \
    --without-python || exit
    make -j4
    make install

    ln $LOCAL_OUTDIR/arm7/lib/lib{x,z}slt.a 

    # find ./ -iname *.a | grep -v $LOCAL_OUTDIR | xargs -L 1 -I '{}' cp '{}' $LOCAL_OUTDIR/arm7
    # cp -rvf lib*.a $LOCAL_OUTDIR/arm7

    make clean 2> /dev/null
    setenv_arm7s

    export DISTDIR=`pwd`/$LOCAL_OUTDIR/arm7s

    ./configure --prefix="${DISTDIR}" \
    --host=armv7s-apple-darwin12.5.0 \
    --enable-static \
    --disable-shared \
    --with-libxml-include-prefix="${SDKROOT}"/usr/include \
    --with-libxml-libs-prefix="${SDKROOT}"/usr/lib \
    --without-crypto \
    --without-python || exit
    make -j4
    make install

    ln $LOCAL_OUTDIR/arm7s/lib/lib{x,z}slt.a 

    # find ./ -iname *.a | grep -v $LOCAL_OUTDIR | xargs -L 1 -I '{}' cp '{}' $LOCAL_OUTDIR/arm7s
    # cp -rvf lib*.a $LOCAL_OUTDIR/arm7s

    create_outdir_lipo
    mkdir -p $GLOBAL_OUTDIR/lib && cp -rvf $LOCAL_OUTDIR/lib/lib*.a $GLOBAL_OUTDIR/lib
    mkdir -p $GLOBAL_OUTDIR/include && cp -rvf $LOCAL_OUTDIR/arm7/include/* $GLOBAL_OUTDIR/include

    cd ..

    echo "Finished!"

Based on Archie's answer, this script (with XCode 5 command line tools) generates a multi-architecture libzslt suitable for inclusion in a project, compatible with iOS 6 and iOS 7 projects (though I haven't included iOS 7 64 bit).

This solution assumes libxslt-1.1.28 is unpacked and in the same directory as the script.

The script creates a directory dependencies which contains the header and lib files. You can include them in an Xcode project by adjusting the header and linker search paths.



    #!/bin/sh
    # build.sh

    GLOBAL_OUTDIR="`pwd`/dependencies"
    LOCAL_OUTDIR="outdir"
    XSLT_LIB="`pwd`/libxslt-1.1.28"

    IOS_BASE_SDK="7.0"
    IOS_DEPLOY_TGT="6.0"

    sed_patch_file()
    {
        FILE="${1}"
        shift
        sed ${1+"$@"}  "${FILE}".new
        if ! diff -q "${FILE}" "${FILE}".new >/dev/null; then
            cat "${FILE}".new > "${FILE}"
        fi
        rm "${FILE}".new
    }

    patch_libxslt() {
        export LIBXSLT_VERSION=1.1.28
        echo "*** Changing symbol names"
        find libxslt-"${LIBXSLT_VERSION}" -name '*.[ch]' -print | while read FILE; do
                sed_patch_file "${FILE}" -E 's%([^[:alnum:]_/"]|^)xslt([A-Z])%\1zslt\2%g'
        done

            # Disable build of xsltproc which fails to link
        sed_patch_file libxslt-"${LIBXSLT_VERSION}"/Makefile.in -E '/^[[:space:]]xsltproc \\$/d'
    }

    setenv_all()
    {
        unset LIBRARIES
        export LIBRARIES=${SDKROOT}/usr/lib
        echo "*** LIBRARIES: ${LIBRARIES}"

        # Add internal libs
        export LDFLAGS="--sysroot=${SDKROOT} $LDFLAGS -L${LIBRARIES}"
        export CFLAGS="--sysroot=${SDKROOT} $CFLAGS -I${SDKROOT}/usr/lib/gcc/${ARCH}/${GCC_VERSION}/include -I${SDKROOT}/usr/include -arch ${ARCH} -Os -pipe ${CPPFLAGS}"

        export CXX="$PLATFORM_BIN_DIR/g++"
        export CC="$PLATFORM_BIN_DIR/gcc"

        export LD=$TOOLROOT/ld
        export AR=$TOOLROOT/ar
        export AS=$TOOLROOT/as
        export NM=$TOOLROOT/nm
        export RANLIB=$TOOLROOT/ranlib
        export CPPFLAGS=$CFLAGS
        export CXXFLAGS=$CFLAGS

        export CXXFLAGS="${CFLAGS}"
    }

    setenv_arm7()
    {
        unset LN DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM CXXCPP RANLIB LDFLAGS CPPFLAGS CXXFLAGS DYLD_LIBRARY_PATH ARCH PLATFORM_BIN_DIR TOOLROOT DISTDIR

        export ARCH=armv7
        export DEVROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
        export SDKROOT=$DEVROOT/SDKs/iPhoneOS$IOS_BASE_SDK.sdk
        export PLATFORM_BIN_DIR=/Applications/Xcode.app/Contents/Developer/usr/bin
        export TOOLROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin    

        export DYLD_LIBRARY_PATH="$SDKROOT/usr/lib"

        export CFLAGS="-arch armv7 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT -I$SDKROOT/usr/include/"

        setenv_all
    }

    setenv_arm7s()
    {
        unset LN DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM CXXCPP RANLIB LDFLAGS CPPFLAGS CXXFLAGS DYLD_LIBRARY_PATH ARCH PLATFORM_BIN_DIR TOOLROOT DISTDIR

        export ARCH=armv7s
        export DEVROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
        export SDKROOT=$DEVROOT/SDKs/iPhoneOS$IOS_BASE_SDK.sdk
        export PLATFORM_BIN_DIR=/Applications/Xcode.app/Contents/Developer/usr/bin
        export TOOLROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin    

        export DYLD_LIBRARY_PATH="$SDKROOT/usr/lib"

        export CFLAGS="-arch armv7s -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT -I$SDKROOT/usr/include/"

        setenv_all
    }

    setenv_i386()
    {
        unset LN DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM CXXCPP RANLIB LDFLAGS CPPFLAGS CXXFLAGS DYLD_LIBRARY_PATH ARCH PLATFORM_BIN_DIR TOOLROOT DISTDIR

        export ARCH=i386
        export DEVROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer
        export SDKROOT=$DEVROOT/SDKs/iPhoneSimulator$IOS_BASE_SDK.sdk
        export PLATFORM_BIN_DIR=$DEVROOT/usr/bin
        export TOOLROOT=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

        export CFLAGS="-arch i386 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT"

        setenv_all
    }

    create_outdir_lipo()
    {
        for lib_i386 in `find $LOCAL_OUTDIR/i386 -name "lib*\.a"`; do
            lib_arm7=`echo $lib_i386 | sed "s/i386/arm7/g"`
            lib_arm7s=`echo $lib_i386 | sed "s/i386/arm7s/g"`
            lib=`echo $lib_i386 | sed "s/i386\///g"`
            mkdir -p $(dirname $lib)
            cmd="xcrun -sdk iphoneos lipo -arch armv7 $lib_arm7 -arch i386 $lib_i386 -arch armv7s $lib_arm7s -create -output $lib"
            echo $cmd
            $cmd
        done
    }

    merge_libfiles()
    {
        DIR=$1
        LIBNAME=$2

        cd $DIR
        for i in `find . -name "lib*.a"`; do
            $AR -x $i
        done
        $AR -r $LIBNAME *.o
        rm -rf *.o __*
        cd -
    }

    #######################
    # libxslt
    #######################

    patch_libxslt

    cd $XSLT_LIB
    rm -rf $LOCAL_OUTDIR
    mkdir -p $LOCAL_OUTDIR/arm7 $LOCAL_OUTDIR/i386

    make clean 2> /dev/null
    setenv_i386

    export DISTDIR=`pwd`/$LOCAL_OUTDIR/i386

    ./configure --prefix="${DISTDIR}" \
    --enable-static \
    --disable-shared \
    --with-libxml-include-prefix="${SDKROOT}"/usr/include \
    --with-libxml-libs-prefix="${SDKROOT}"/usr/lib \
    --without-crypto \
    --without-python || exit
    make "CC=$CC" "CFLAGS=$CFLAGS" "AR=$AR"
    make install

    ln $LOCAL_OUTDIR/i386/lib/lib{x,z}slt.a 

    # find ./ -iname *.a | grep -v $LOCAL_OUTDIR | xargs -L 1 -I '{}' cp '{}' $LOCAL_OUTDIR/i386
    # cp -vf lib*.a $LOCAL_OUTDIR/i386

    make clean 2> /dev/null
    setenv_arm7

    export DISTDIR=`pwd`/$LOCAL_OUTDIR/arm7

    ./configure --prefix="${DISTDIR}" \
    --host=armv7-apple-darwin12.5.0 \
    --enable-static \
    --disable-shared \
    --with-libxml-include-prefix="${SDKROOT}"/usr/include \
    --with-libxml-libs-prefix="${SDKROOT}"/usr/lib \
    --without-crypto \
    --without-python || exit
    make -j4
    make install

    ln $LOCAL_OUTDIR/arm7/lib/lib{x,z}slt.a 

    # find ./ -iname *.a | grep -v $LOCAL_OUTDIR | xargs -L 1 -I '{}' cp '{}' $LOCAL_OUTDIR/arm7
    # cp -rvf lib*.a $LOCAL_OUTDIR/arm7

    make clean 2> /dev/null
    setenv_arm7s

    export DISTDIR=`pwd`/$LOCAL_OUTDIR/arm7s

    ./configure --prefix="${DISTDIR}" \
    --host=armv7s-apple-darwin12.5.0 \
    --enable-static \
    --disable-shared \
    --with-libxml-include-prefix="${SDKROOT}"/usr/include \
    --with-libxml-libs-prefix="${SDKROOT}"/usr/lib \
    --without-crypto \
    --without-python || exit
    make -j4
    make install

    ln $LOCAL_OUTDIR/arm7s/lib/lib{x,z}slt.a 

    # find ./ -iname *.a | grep -v $LOCAL_OUTDIR | xargs -L 1 -I '{}' cp '{}' $LOCAL_OUTDIR/arm7s
    # cp -rvf lib*.a $LOCAL_OUTDIR/arm7s

    create_outdir_lipo
    mkdir -p $GLOBAL_OUTDIR/lib && cp -rvf $LOCAL_OUTDIR/lib/lib*.a $GLOBAL_OUTDIR/lib
    mkdir -p $GLOBAL_OUTDIR/include && cp -rvf $LOCAL_OUTDIR/arm7/include/* $GLOBAL_OUTDIR/include

    cd ..

    echo "Finished!"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文