Xcode clang link:构建动态框架(或dylib)不嵌入依赖项 [英] Xcode clang link: Build Dynamic Framework (or dylib) not embed dependencies

查看:1462
本文介绍了Xcode clang link:构建动态框架(或dylib)不嵌入依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iOS构建一个动态框架。它需要从代码或其他库中引用一些符号,但我不想将它们链接到框架中。



这可以在构建静态库时实现,只需要设置搜索路径并确保它们不包含在目标的构建阶段。



但是当构建动态框架或dylib时,此结果未定义符号错误。我尝试过各种链接选项,例如 -l <​​/ code> -weak_library -weak_framework -I -rpath -rpath-link



链接命令如下所示:

  clang -arch x86_64 -dynamiclib 
-isysroot * iPhone_SDK_PATH *
* OPTIONS_NOT_IMPORTANT *
-install_name @ rpath / Foo.framework / Foo
-Xlinker -rpath -Xlinker @ executable_path / Frameworks
-Xlinker -rpath -Xlinker @ loader_path / Frameworks
-Xlinker -rpath -Xlinker * BUILD_PATH *
-mios-simulator-version-min = 7.0
-Xlinker -no_deduplicate
-Xlinker -objc_abi_version
-Xlinker 2
-fobjc-arc -fobjc-link-runtime
-framework Foundation
-single_module
-compatibility_version 1
-current_version 1
-Xlinker -dependency_info
-Xlinker * BUILD_PATH * / Foo.build / Objects-normal / x86_64 / Foo_dependency_info.dat
-o * BUILD_PATH * / Foo.framework / clang使用ld命令创建最终链接,使用ld命令来创建最终的链接,我检查了手册,发现 -U -undefined 可以忽略未定义的符号。


-U symbol_name


指定symbol_name没有定义。对于two_levelnamespace,生成的符号将被标记为dynamic_lookup,这意味着dyld将搜索所有加载的图片。


b
$ b


指定如何处理未定义的符号。选项包括:error,warning,suppress或dynamic_lookup。默认为错误。



所以最终的解决方案设置为 -Wl ,-undefined,dynamic_lookup OTHER_LDFLAGS ,还要确保搜索路径设置正确。它工作。


I’m building a dynamic framework for iOS. It needs reference some symbols from code or other libraries, but I not want link them into the framework.

This can be achieved when build an static library, just setup search path and make sure them not included in target’s build phases.

But when build a dynamic framework or dylib, this result undefined symbol error. I tried all kinds of link options, eg -l -weak_library -weak_framework -I -rpath -rpath-link. But none works.

The link command looks like this:

clang -arch x86_64 -dynamiclib
    -isysroot *iPhone_SDK_PATH* 
    *OPTIONS_NOT_IMPORTANT* 
    -install_name @rpath/Foo.framework/Foo
    -Xlinker -rpath -Xlinker @executable_path/Frameworks
    -Xlinker -rpath -Xlinker @loader_path/Frameworks
    -Xlinker -rpath -Xlinker *BUILD_PATH*
    -mios-simulator-version-min=7.0
    -Xlinker -no_deduplicate
    -Xlinker -objc_abi_version
    -Xlinker 2 
    -fobjc-arc -fobjc-link-runtime
    -framework Foundation
    -single_module
    -compatibility_version 1
    -current_version 1
    -Xlinker -dependency_info
    -Xlinker *BUILD_PATH*/Foo.build/Objects-normal/x86_64/Foo_dependency_info.dat 
    -o *BUILD_PATH*/Foo.framework/Foo

解决方案

clang use ld command to make the final link, I checked the manual and found -U and -undefined can ignore undefined symbols.

-U symbol_name

Specified that it is ok for symbol_name to have no definition. With two_levelnamespace, the resulting symbol will be marked dynamic_lookup which means dyld will search all loaded images.

-undefined treatment

Specifies how undefined symbols are to be treated. Options are: error, warning, suppress, or dynamic_lookup. The default is error.

So the final solution is set -Wl,-undefined,dynamic_lookup to OTHER_LDFLAGS, also make sure search path set correctly. It works.

这篇关于Xcode clang link:构建动态框架(或dylib)不嵌入依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆