如何使用Xcode创建动态库(dylib)? [英] How do I create a dynamic library (dylib) with Xcode?

查看:1374
本文介绍了如何使用Xcode创建动态库(dylib)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Xcode中构建一些命令行实用程序(普通C,没有可可).我希望他们所有人都使用我的自定义版本的libpng,并且希望通过在所有可执行文件之间共享库的一个副本来节省空间(我不介意与他们重新分发.dylib).

I'm building few command-line utilities in Xcode (plain C, no Cocoa). I want all of them to use my customized version of libpng, and I want to save space by sharing one copy of the library among all executables (I don't mind re-distributing .dylib with them).

我需要做些魔术来获取libpng导出符号吗?

Do I need to do some magic to get libpng export symbols?

使用库链接二进制文件" 是否静态构建阶段链接?

Does "Link Binary With Libraries" build phase link statically?

Apple的文档提到使用dlopen在运行时加载库,但是如何使Xcode创建可执行文件而不抱怨缺少符号?

Apple's docs mention loading of libraries at run time with dlopen, but how I can make Xcode create executable without complaining about missing symbols?

我想我已经解决了:

  • libpng链接不正确,因为我已经构建了32/64位可执行文件和32位库.库和可执行文件的构建设置必须匹配.

  • libpng wasn't linking properly, because I've built 32/64-bit executables and 32-bit library. Build settings of the library and executables must match.

libpng的config.h需要具有大量的定义,例如#define FEATURE_XXX_SUPPORTED

libpng's config.h needs to have tons of defines like #define FEATURE_XXX_SUPPORTED

使用库链接二进制文件" 构建阶段可以很好地处理动态库,并且DYLD_FALLBACK_LIBRARY_PATH环境变量对于从应用程序包中加载.dylib是必需的.

"Link Binary With Libraries" build phase handles dynamic libraries just fine, and DYLD_FALLBACK_LIBRARY_PATH environmental variable is neccessary for loading .dylibs from application bundle.

推荐答案

您可能需要确保所构建的动态库具有导出的符号文件,该文件列出了应从库中导出的内容.这只是符号的平面列表,每行一个,用于导出.

You probably need to ensure that the dynamic library you build has an exported symbols file that lists what should be exported from the library. It's just a flat list of the symbols, one per line, to export.

此外,在构建动态库时,它会在其中嵌入一个安装名称,默认情况下,该名称是其构建路径.随后,与之链接的所有内容都将首先在指定的路径中查找它,然后才在DYLD_FALLBACK_LIBRARY_PATH下搜索一组(小的)默认路径. /Darwin/Reference/ManPages/man1/dyld.1.html"rel =" noreferrer"title =" dyld(1)手册页> dyld(1)手册页.

Also, when your dynamic library is built, it gets an install name embedded within it which is, by default, the path at which it is built. Subsequently anything that links against it will look for it at the specified path first and only afterwards search a (small) set of default paths described under DYLD_FALLBACK_LIBRARY_PATH in the dyld(1) man page.

如果要将这个库放在可执行文件旁边,则应调整其安装名称以引用该库.只需在Google中搜索安装名称",就会获得大量有关此操作的信息.

If you're going to put this library next to your executables, you should adjust its install name to reference that. Just doing a Google search for "install name" should turn up a ton of information on doing that.

这篇关于如何使用Xcode创建动态库(dylib)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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