符号重复(工作空间中的两个项目使用相同的代码) [英] Duplicate symbols (two projects in a workspace use the same code)

查看:178
本文介绍了符号重复(工作空间中的两个项目使用相同的代码)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

A是一个模块项目.有一些测试目标,相关的可重用代码在单独的(静态库)目标中编译. A使用第三方Lumberjack日志记录库.伐木工人代码只是放入了项目中.

B是一个不同的模块项目,但是与A具有相同的属性.

C是主要项目.它取决于AB.它链接AB的库.

编译C将导致重复的Lumberjack符号.

我如何有多个单独的模块项目,以便...

  1. 他们彼此不认识
  2. 使用相同的第三方代码,
  3. 可以自行编译和测试,
  4. 包含在主项目中,没有重复的问题吗?

解决方案

由于您的目标是OSX,因此解决该问题的方法是将Lumberjack构建为框架(而不是在A和B模块中链接源代码),并且然后在需要的地方使用该框架(即,在使用A或B模块的任何项目中).

事实上,Lumberjack已经包含一个将构建Lumberjack.framework的项目,请检查以下内容:CocoaLumberjack/Xcode/LumberjackFramework/Desktop/Lumberjack.xcodeproj.

对此进行详细说明,您将像现在一样定义A和B模块,但不会在其中删除Lumberjack源代码. 相反,您要做的是,每当要在可执行文件中使用静态库(例如,测试目标)时,都将库添加到目标中,并且将伐木工人框架(与使用OSX SDK框架完全一样)添加到伐木工人框架中./p>

添加动态框架只是删除源"的另一种方式,如果需要的话,但可以正确完成.

当您要在C项目中同时使用A和B时,请将静态库和Lumberjack框架都添加到C中.

如您所见,这种方式将符合您的所有四个要求,而以引入一个依赖性为代价:您需要在静态库文档中明确说明它们依赖于伐木工人框架.这实际上不是什么大问题,因为后者可以在自己的项目中使用,而且任何人都可以自行构建.

如果您想改进此依赖项的处理方式,可以使用cocoapods(cocoapods是与您的库相关联的文件,描述了其依赖关系,因此,在安装库时,cocoapods系统也会自动安装依赖项).但这是高度可选的.一个单一的依赖关系对于记录或遵守并不是一个大问题.

希望这能回答您的问题.

A is a module project. There are some test targets and the relevant reusable code is compiled in a separate (static library) target. A uses the third party Lumberjack logging library. The Lumberjack code was simply dropped into the project.

B is a different module project, but otherwise it has the same properties as A.

C is the main project. It depends on A and B. It links the libraries of A and B.

Compiling C will result in duplicate Lumberjack symbols.

How can I have multiple separate module projects so that...

  1. they don't know of each other,
  2. use the same third party code,
  3. can be compiled and tested on their own,
  4. included in a main project without duplicate issues?

解决方案

Since you are targeting OSX, the solution to your issue is building Lumberjack as a framework (as opposed to link the sources code in your A and B modules) and then using that framework wherever it is required (i.e., in any project using A or B modules).

Indeed, Lumberjack already includes a project that will build a Lumberjack.framework, check this: CocoaLumberjack/Xcode/LumberjackFramework/Desktop/Lumberjack.xcodeproj.

Elaborating more on this, you would define your A and B modules as you are doing now, but without dropping Lumberjack source code in it. What you do instead is, whenever you want to use the A static library in a executable (say, your test target), you add the library to the target and also the lumberjack framework (exactly as you do with OSX SDK frameworks).

Adding the dynamic framework is just a different way to "drop the sources", if you want, but done properly.

When you want to use both A and B in a C project, you add both static libraries and your Lumberjack framework to C.

As you can see, this way of doing will comply with all your four requirements, at the expense of introducing one dependency: you need to make clear in your static libraries documentation that they depend on the Lumberjack framework. This is actually not a big issue, since the latter is available in its own project and any one will be able to build it on his own.

If you want to improve on the handling of this dependencies, cocoapods are the way to go (a cocoapod is a file associated to your library which describes its dependencies, so when you install your library, the cocoapods system will automatically install also the dependencies). But this is highly optional. One single dependency is not a big issue to document or comply with.

Hope this answers your question.

这篇关于符号重复(工作空间中的两个项目使用相同的代码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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