前缀静态库iOS [英] Prefix Static Library iOS

查看:254
本文介绍了前缀静态库iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个iOS静态库(根据 https://github.com/jverkoey/iOS) -framework )。我依靠SBJson和AFNetworking。我想包括这些库,以避免版本问题和安装简单;为此,我需要为这些库添加前缀以避免命名冲突。

I'm building an iOS static library (as per https://github.com/jverkoey/iOS-Framework). I depend on SBJson and AFNetworking. I would like to include these libraries to avoid version issues and for installation simplicity; to do so, I need to prefix these libraries to avoid naming conflicts.

如何以简单的方式为其他静态库添加前缀?

How can I prefix other static libraries in a simple way?

理想情况下,它将成为我构建过程的一部分。关于如何以理智的方式重构和重命名的提示不太理想,但可接受。

Ideally, it would be part of my build process. Less ideally, but acceptable, are tips on how to refactor and rename in a sane manner.

推荐答案

唯一安全的解决方案(其他而不是完全不这样做)是在所有符号上构建任何具有前缀的依赖项。

The only safe solution (other than not doing this at all) is to build any dependencies with a prefix on all symbols.

最简单的前缀方法是经典的查找和替换。这很容易出错,因此最好使用 nm -a 命中.a并搜索任何非前缀符号的结果。

The easiest method of prefixing is the classic "find-and-replace". This is error-prone, so it's a good idea to hit the .a with nm -a and scour the results for any non-prefixed symbols.

第二种更安全的方法是使用两遍编译过程。

A second, much safer method is to use a two-pass compilation process.


  • 第一遍构建依赖项目并运行 nm 将所有符号转储到头文件中。

  • 第二遍再次构建依赖项目,但是这次使用在预编译头中导入的生成的前缀头文件。在您从框架中的依赖项引用符号的任何地方都必须使用此前缀标头,以便正确引用重命名的符号。

  • The first pass builds the dependent project and runs nm to dump all symbols into a header file.
  • The second pass builds the dependent project again, but this time with the generated prefix header file imported in the precompiled header. This prefix header must be used anywhere you reference symbols from the dependency in your framework in order to properly refer to the renamed symbols.

作为参考,我们在 Nimbus 中使用它来生成Nimbus前缀标题:
< a href =https://github.com/jverkoey/nimbus/blob/master/scripts/generate_namespace_header =noreferrer> https://github.com/jverkoey/nimbus/blob/master/scripts/generate_namespace_header

For reference, we use this with Nimbus to generate the Nimbus prefix headers: https://github.com/jverkoey/nimbus/blob/master/scripts/generate_namespace_header

这允许您分发带有Nimbus嵌入式前缀版本的.framework。

This allows you to distribute a .framework with a prefixed version of Nimbus embedded.

现在,您可以将生成的.a链接到您的框架中,并在第三方开发人员不可避免地将其自己的依赖项版本链接到项目中时安全地避免任何链接器冲突。

You can now link the resulting .a into your framework and safely avoid any linker conflicts when a third party developer inevitably links their own version of the dependency into their project.

这篇关于前缀静态库iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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