简体   繁体   English

应用程序捆绑包Mac os X中的动态库

[英]dynamic library in application bundle Mac os X

I am using dynamic libraries in my application and now i need to distribute this application to users. 我在应用程序中使用动态库,现在我需要将此应用程序分发给用户。 I want to put all the dynamic libraries in bundle instead of installing the dynamic libraries in lib,usr/lib .. etc , so that it would be clean deployment and easy to maintain. 我想将所有动态库放在包中,而不是在lib,usr / lib .. etc等目录中安装动态库,这样它就可以干净部署并易于维护。 Problem is when i put dyanamic libraries in Xcode application as a framework its not working .Please help me how can i do this ? 问题是当我将动态库放在Xcode应用程序中作为框架时,它不起作用。请帮助我该怎么做? I want to make sure my application uses dynamic libraries from bundle not from system libs . 我想确保我的应用程序使用bundle中的动态库,而不是系统libs中的动态库。 Please advice 请指教

Dunno if there's a way to specify that inside Xcode or not, but for our app we use a build script that includes some code like the following. Dunno是否有办法在Xcode内指定它,但是对于我们的应用程序,我们使用一个包含以下代码的构建脚本。 The code uses Apple's install_name_tool utility to modify the application so that instead of pointing to /usr/lib/libsndfile.so, it points to a libsndfile.so path that is in the application's package instead. 该代码使用Apple的install_name_tool实用程序来修改应用程序,以便它指向应用程序包中的libsndfile.so路径,而不是指向/usr/lib/libsndfile.so。

Note this is just a cut-down script excerpt to give you an idea; 注意,这只是一个简短的脚本摘录,可以使您有所了解。 it will probably require some tweaking before it works for you (and of course you'll need to modify it to operate on other libraries besides libsndfile if that is what you want): 它可能需要先进行一些调整,然后才能为您工作(当然,如果需要的话,您需要对其进行修改以在libsndfile之外的其他库上运行):

#!/bin/bash -e

BINARY="MyAppFolder/MyAppName"
FRAMEW_FOLDER="MyAppFolder/MyAppName/Contents/Frameworks/"

function DoInstallNameTool {
    xLIB="$1"
    xLIB_NAME="$2"
    xBINARY="$3"
    echo install_name_tool -change \"${xLIB}\" \"@executable_path/../Frameworks/${xLIB_NAME}\" \"${xBINARY}\"
    install_name_tool -change ${xLIB} "@executable_path/../Frameworks/${xLIB_NAME}" "${xBINARY}"
}

for LIB in $(otool -L "${BINARY}"|grep libsndfile|cut -d '(' -f -1)
do
    echo "Handling Lib: $LIB"
    LIB_NAME=$(basename "$LIB")
    echo "    Adding ${LIB_NAME}"
    cp -Rf "${LIBSNDFILE_DIR}/src/.libs/${LIB_NAME}" "${FRAMEW_FOLDER}"

    DoInstallNameTool "$LIB" "$LIB_NAME" "$BINARY"
done

After the script runs, you can do a 脚本运行后,您可以执行

otool -L ./MyApp.app/Contents/MacOS/MyApp

to print out all the shared libraries the app depends on, to verify that the script worked (or if it didn't work, to see what /usr/lib/* libraries the app is still dynamically linked to) 打印出应用程序所依赖的所有共享库,以验证脚本是否有效(或者,如果脚本不起作用,则查看应用程序仍动态链接到的/ usr / lib / *库)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM