如何使用Xcode将多个dylib打包为单个OS-X Framework

时间:2015-12-29 15:52:02

标签: xcode macos boost

我正在尝试将一组google boost库打包为一个OS-X私有框架,并且失败了。

我成功地在Mac上使用boosts build-tools(b2,bjam)来构建我需要的boost库的静态lib(.a)和动态lib(.dylib)版本。

我在Xcode中创建了一个框架目标(配置为私有框架)。我将它与我需要的7个dylib相关联,并设法将Headers复制到位,并将实际的dylib复制到框架的可执行文件目录中,以便它们与新的" boost& #34;框架。

然而," top"框架的动态库 - (名为" boost" on diet)不会导出这7个库中的任何符号。

所以我可以构建我的框架 - 但不能使用它。

我发现尝试自动(使用脚本)创建一个iOS"框架"来自boost的(使用内部静态库),但是这个脚本很旧,并且不适用于以后的boost版本,而且 - 它不是Xcode项目,只是一个脚本。

我试图找到如何通过我的" boost"重新导出链接的.dylibs的符号。动态的lib,但无法理解。

任何人的想法? 我真的很沮丧。

2 个答案:

答案 0 :(得分:0)

这很复杂。您可以尝试,如果此构建脚本让您更接近解决方案:

https://gist.github.com/JanX2/80721c30192e64ed124e

答案 1 :(得分:0)

嗯,不是没有汗水和眼泪,我终于得到了它的工作,这是所涉及的技巧。 在完成我在原始问题中提到的所有事情之后,您还必须:

  1. 在构建设置中,找到“重新导出的库名称”,并添加dylib,名称如下:boost_iostreams boost_locale boost_regex boost_signals boost_system boost_thread boost_filesystem(这需要一天 - 为什么你需要删除“lib”和“ .dylib“以及重新导出dylib意味着什么。”
  2. 在构建阶段,在编译之前添加一个运行脚本阶段(您可以将其命名为Run Script - Fix boost dylibs,并添加以下脚本(可能需要根据您放置boost build dir的位置进行更改)
  3. #!/bin/bash  
    
    src_boost_dylib_dir=$SRCROOT/../../../boost_1_59_0_lib/dylib
    
    dest_boost_dylib_dir=$CONFIGURATION_BUILD_DIR/$EXECUTABLE_FOLDER_PATH
    
    boost_dylibs=( libboost_filesystem.dylib libboost_iostreams.dylib  libboost_locale.dylib libboost_regex.dylib libboost_signals.dylib  libboost_system.dylib libboost_thread.dylib)
    
    for bdl in "${boost_dylibs[@]}"; do  
        echo Fixing boost dylib:$bdl
        # at runtime, 'boost' loads its re-exported dylibs for other clients (such as AP) linked to boost. To find them, it must look in the same directory where boost is.
        install_name_tool -id @loader_path/$bdl $src_boost_dylib_dir/$bdl
        # make all dependent boost dylibs also relative to @loader_path, so that they can find each other in runtime.
    
        dependencies=`otool -L $src_boost_dylib_dir/$bdl | grep  "^\slibboost_" | awk -F' ' '{ print $1 }'`
        for dependency_dylib in "${dependencies[@]}"; do
            if [ "${dependency_dylib}" == "" ]; then
                continue
            fi
            echo Dependency:$dependency_dylib
            install_name_tool -change $dependency_dylib  @loader_path/$dependency_dylib $src_boost_dylib_dir/$bdl
    
        done
    done
    
    1. 在问题中,在Linkage阶段之后添加一个copy-files构建阶段,将dylib复制到“Executables”目录中,因此它们与构建的产品(boost dylib)一起存在。

    2. 在该阶段之后,复制另一个名为Run Script - Create symlink to reexported dylibs的运行脚本阶段。添加以下脚本:

    3. # Create symlinks for all re-exported dylibs, at the framework's top level. They must be also relative to the framework directory.
      cd $CONFIGURATION_BUILD_DIR/$WRAPPER_NAME
      ln -Ffsv Versions/Current/libboost_*.dylib .
      

      你应该完成。