重复符号:在静态库B中包含静态库A,在XCode项目中也包含库A和B. [英] Duplicate symbol: Include static lib A in static lib B, also include lib A and B in XCode Project

查看:132
本文介绍了重复符号:在静态库B中包含静态库A,在XCode项目中也包含库A和B.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试为应用程序开发构建一组可重用的库,但我开始遇到问题。

I've been trying to build up a set of reusable libraries for app development, but I'm starting to run into a problem.

我的一个静态libs是一组通用方法(Objective-C Foundation类的类别,用于提高它们的可用性),我倾向于在每个项目中使用它们。 (我们将其称为Lib A ...即XCode项目A生成libProjectA.a)

One of my static libs is a set of general use methods (categories on Objective-C Foundation classes to improve their usability) which I tend to use in every project. (We'll call it Lib A... i.e. XCode project A produces libProjectA.a)

然后我有其他静态库,包含数学专用代码的东西,等等(我们称之为Lib B.)Lib B链接到Lib A,因为它需要使用一些通用功能。 (即XCode项目B与libProjectA.a链接并生成libProjectB.a)

Then I have other static libs, things that contain specialized code for math, etc. (We'll call it Lib B.) Lib B links to Lib A because it needs to use some of that general functionality. (i.e. XCode project B links with libProjectA.a and produces libProjectB.a)

在我的XCode项目中,我想包含并依赖于Lib A,因为它有我的一般使用我一直使用的东西。我还想包含并依赖Lib B,因为我需要专门的数学功能。 (即我的应用程序项目想要与libProjectA.a和libProjectB.a链接)

In my XCode project, I want to include and depend on Lib A because it has my general use stuff that I use all the time. I also want to include and depend on Lib B because I need that specialized math functionality. (i.e. my app Project wants to link with libProjectA.a and libProjectB.a)

然而,当我尝试构建我的XCode项目时,我得到重复符号的错误,因为Lib A中定义的符号也在Lib B中定义。

However, when I try to build my XCode project I get errors for duplicate symbols, because the symbols that are defined in Lib A are also defined in Lib B.

ld: duplicate symbol _OBJC_METACLASS_$_Foo in /Users/kenny/xcode_build/Release-iphonesimulator/lib_ApplicationCore.a(Foo.o) and /Users/kenny/xcode_build/Release-iphonesimulator/lib_SpecializedMath.a(Foo.o)

如何解决这个问题?我想开发可重用的库来加速我的应用程序开发,并通过经过测试/改进的代码来提高稳定性。我是从错误的角度来看待这个吗?我正在为iOS开发,所以我不能使用dylib,它们必须是静态的。

How can I get around this problem? I want to develop reusable libraries to speed my app development as well as increase stability through tested/refined code. Am I approaching this from the wrong perspective? I'm developing for iOS so I can't use dylibs, they must be static.

当我们的项目彼此相互依赖时,如何将这些库包含在我的项目中并避免重复的符号?

How can I include these libraries in my project when they are interdependent upon each other and avoid the duplicate symbols?

推荐答案

虽然Lib B依赖于Lib A,但实际上并不想放置所有对象A到B,这就是你通过它的外观所做的。我不确定你是如何管理的,但是我想你在建造自由B时你是否与Lib A有联系?如果是这样,只需从Lib B的构建行中省略Lib A.所有来自Lib A的符号都在Lib B中未定义。

Although Lib B depends on Lib A you don't actually want to put all the objects from A into B which is what you've done by the looks of it. I'm not sure how you managed that but I would imagine when you built Lib B you linked against Lib A? If so, just omit Lib A from the build line for Lib B. All the symbols from Lib A are meant to be undefined in Lib B.

静态库只是档案对象文件,所以这两个应该完全分开。当你需要链接Lib B时,也可以指定Lib A.

Static libraries are just archives of object files so the two should be completely separate. When you need to link against Lib B just specify Lib A as well.

这篇关于重复符号:在静态库B中包含静态库A,在XCode项目中也包含库A和B.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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