如何在Xcode 4中使用dylib文件创建一个工作框架

如何在Xcode 4中使用dylib文件创建一个工作框架,第1张

概述我在Xcode中创建了一个新的可可框架,除了支持文件之外,删除了其中包含的所有库和文件。 我有2个文件: add.h#ifndef add_add_h#define add_add_hvoid add(void);#endif 和 add.c#include <stdio.h>#include "add.h"void add(void){ printf("adfdi @H_403_4@ 我在Xcode中创建了一个新的可可框架,除了支持文件之外,删除了其中包含的所有库和文件。 @H_403_7@

@H_403_7@我有2个文件:

@H_403_7@

add.h#ifndef add_add_h#define add_add_hvoID add(voID);#endif
@H_403_7@和

@H_403_7@

add.c#include <stdio.h>#include "add.h"voID add(voID){    printf("adfding");}
@H_403_7@在构建阶段,我添加add.c来编译源和add.h以编译头public。项目构建没有问题,但在框架中没有dylib文件,当我将框架拖放到另一个项目时,它表示找不到dylib文件。

@H_403_7@

dyld: library not loaded: @rpath/add.framework/Versions/A/add   Referenced from: /Users/vjoukov/Desktop/Projects/test/build/DeBUG/test.app/Contents/MacOS/test  Reason: image not found
@H_403_7@我如何做一个简单的框架并保留dylib文件?

@H_403_4@解决方法 我想你误会了错误消息。 @H_403_7@

@H_403_7@一个.framework作为一个动态库,但是在.framework文件夹内不会有任何Mach-O可加载对象文件,其中有一个实际的.dylib文件扩展名。

@H_403_7@有几个原因可能会在运行时从dyld(动态链接库加载器)获取该错误消息。第一个是您在构建过程中忘记将.frameworks复制到构建的应用程序包中。虽然它们可以复制到应用程序包中的任何位置,但传统的地方在Appname.app/Contents/Frameworks/中。如果您还没有这样做,请选择项目>新建阶段>新建文件构建阶段。将目标d出窗口更改为框架,如下图所示。

@H_403_7@然后,您将会将框架的图标拖放到文件夹中,以便在构建过程中将其复制。

@H_403_7@框架在运行时无法找到的第二个也是更可能的原因是您尚未为主可执行文件指定任何运行路径搜索路径。 (这是必需的,因为我们从错误消息中看到,您的框架是使用较新的@ rpath /样式安装名称(@ rpath / add.framework / Versions / A / add)构建的,而不是较旧的@ executable_path /或@ loader_path / styles)。

@H_403_7@如果您将自定义框架复制到上述位置,则可以添加@loader_path /../框架的运行路径搜索路径条目,如下图所示:

@H_403_7@以下摘录,说明在运行时如何找到动态库是从dyld的联机帮助页面:

@H_403_7@

@H_403_7@DYNAMIC liBRARY LOADING

@H_403_7@Unlike many other operating systems,Darwin does not locate
dependent dynamic librarIEs via their leaf file name. Instead the
full path to each dylib is used (e.g.
/usr/lib/libSystem.B.dylib). But there are times when a full
path is not appropriate; for instance,may want your binarIEs to be
installable in anywhere on the disk. To support that,there are three
@xxx/ variables that can be used as a path prefix. At runtime dyld
substitutes a dynamically generated path for the @xxx/ prefix.

@H_403_7@@executable_path/

@H_403_7@This variable is replaced with the path to the directory
containing the main executable for the process. This is useful for
loading dylibs/frameworks embedded in a .app directory. If the
main executable file is at /some/path/My.app/Contents/MacOS/My
and a framework dylib file is at
/some/path/My.app/Contents/Frameworks/Foo.framework/Versions/A/Foo,
then the framework load path Could be encoded as
@executable_path/../Frameworks/Foo.framework/Versions/A/Foo and the
.app directory Could
be moved around in the file system and dyld will still be able
to load the embedded framework.

@H_403_7@@loader_path/

@H_403_7@This variable is replaced with the path to the directory
containing the mach-o binary which contains the load command using
@loader_path. Thus,in every binary,@loader_path resolves to a
different path,whereas @executable_path always resolves to the
same path. @loader_path is useful as the load path for a
framework/dylib embedded in a plug-in,if the final file system
location of the plugin-in unkNown (so absolute paths cannot be used)
or if the plug-in is used by multiple applications (so
@executable_path cannot be used). If the plug-in mach-o file is at
/some/path/Myfilter.plugin/Contents/MacOS/Myfilter and a
framework dylib file is at
/some/path/Myfilter.plugin/Contents/Frameworks/Foo.framework/Versions/A/Foo,
then the framework load path
Could be encoded as
@loader_path/../Frameworks/Foo.framework/Versions/A/Foo and the
Myfilter.plugin directory Could be
moved around in the file system and dyld will still be able to
load the embedded framework.

@H_403_7@@rpath/

@H_403_7@Dyld maintains a current stack of paths called the run path
List. When @rpath is encountered it is substituted with each
path in the run path List until a loadable dylib if found. The
run path stack is built from the LC_RPATH load commands in the
depencency chain that lead to the current dylib load. You can
add an LC_RPATH load command to an image with the -rpath option
to ld(1). You can even add a LC_RPATH load command path that
starts with @loader_path/,and it will push a path on the run
path stack that relative to the image containing the LC_RPATH.
The use of @rpath is most useful when you have a complex
directory structure of programs and dylibs which can be installed
anywhere,but keep their relative positions. This scenario
Could be implemented using @loader_path,but every clIEnt of a
dylib Could need a different load path because its relative
position in the file system is different. The use of @rpath
introduces a level of indirection that simplIEs things. You
pick a location in your directory structure as an anchor point.
Each dylib then gets an install path that starts with @rpath and
is the path to the dylib relative to the anchor point. Each main
executable is linked with -rpath @loader_path/zzz,where zzz is
the path from the executable to the anchor point. At runtime
dyld sets it run path to be the anchor point,then each dylib is found relative to the anchor point.

@H_403_4@ @H_403_4@ @H_403_4@ @H_403_4@ 总结

以上是内存溢出为你收集整理的如何在Xcode 4中使用dylib文件创建一个工作框架全部内容,希望文章能够帮你解决如何在Xcode 4中使用dylib文件创建一个工作框架所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1071537.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存