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

问题描述 投票:0回答:2

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

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

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

但是,框架的“顶级”动态库 - (在节食时命名为“boost”)不会导出这7个库中的任何符号。

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

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

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

想法有人吗?我真的很沮丧。

xcode macos boost
2个回答
0
投票

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

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


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构建目录的位置进行更改)
#!/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的运行脚本阶段。添加以下脚本:
# 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 .

你应该完成。

© www.soinside.com 2019 - 2024. All rights reserved.