xcode 如何处理来自 3rd 方库的重复符号错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2910205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:23:27  来源:igfitidea点击:

How to handle duplicate symbol error from 3rd party libraries?

iphoneobjective-ccocoa-touchxcode

提问by user230949

I have two 3rd party libraries that seem to use the same class. That should be fine but I'm getting this type of error when building:

我有两个似乎使用相同类的第 3 方库。那应该没问题,但我在构建时遇到这种类型的错误:

ld: duplicate symbol .objc_class_name_CJSONScanner in /Users/myappOne/TapjoyConnect/Frameworks/libTapjoyConnectSimulatorRewardInstall_Ads_Pinch.a(CJSONScanner.o) and /Developer/Projects/BuildOutput/Debug-iphonesimulator/OtherLibrary_d.a(CJSONScanner.o)

How can I handle this issue...

我该如何处理这个问题...

-- EDIT --

- 编辑 -

...if the source files are not available?

...如果源文件不可用?

回答by Cory Kilger

I'm going to assume that these are two third party libraries that have only provided you with the .a files and not the source code. You can use libtool, lipo and ar on the terminal to extract and recombine the files.

我将假设这是两个仅向您提供 .a 文件而不是源代码的第三方库。您可以在终端上使用 libtool、lipo 和 ar 来提取和重组文件。

To see what architectures are in the file:

要查看文件中的架构:

$ lipo -info libTapjoy.a
Architectures in the fat file: libTapjoy.a are: armv6 i386

Then to extract just armv6, for example:

然后只提取 armv6,例如:

$ lipo -extract_family armv6 -output libTapjoy-armv6.a libTapjoy.a
$ mkdir armv6
$ cd armv6
$ ar -x ../libTapjoy-armv6.a

You can then extract the same architecture from the other library into the same directory and then recombine them like so:

然后,您可以将其他库中的相同架构提取到同一目录中,然后像这样重新组合它们:

$ libtool -static -o ../lib-armv6.a *.o

And then finally, after you've done this with each architecture, you can combine them again with lipo:

最后,在对每个架构完成此操作后,您可以再次将它们与 lipo 结合起来:

$ cd ..
$ lipo -create -output lib.a lib-armv6.a lib-i386.a

This should get rid of any duplicate symbols, but will also combine the two libraries into one. If you want to keep them separate, or just delete the duplicate from one library, you can modify the process accordingly.

这应该消除任何重复的符号,但也会将两个库合二为一。如果您想将它们分开,或者只是从一个库中删除重复项,您可以相应地修改流程。

回答by David Smith

Cory Kilger's answer is the right way to go ... just a minor tweak since I don't have the reputation to comment.

科里·基尔格 (Cory Kilger) 的回答是正确的方法……只是一个小小的调整,因为我没有发表评论的声誉。

On my Mac OS 10.8 system, this lipo command is the one I used to make the .a files for use with ar:

在我的 Mac OS 10.8 系统上,这个 lipo 命令是我用来制作 .a 文件以与 ar 一起使用的命令:

lipo -thin armv6 -output libTapjoy-armv6.a libTabjoy.a

The man page for lipo says -extract and -extract_family both produce universal .a files and my ar command won't extract anything from them.

lipo 的手册页说 -extract 和 -extract_family 都生成通用的 .a 文件,我的 ar 命令不会从中提取任何内容。

回答by Mark Bessey

If you have the sources to both static libraries, build one of them without the CJSONScanner class. If you don't you can use "ar" from the command line to extract the CJSONScanner.o from one of the libraries.

如果您拥有两个静态库的源代码,请在不使用 CJSONScanner 类的情况下构建其中之一。如果不这样做,您可以从命令行使用“ar”从库之一中提取 CJSONScanner.o。

There's probably some magic flag you can pass to "ld" to fix this, but I don't know it off hand.

可能有一些魔法标志你可以传递给“ld”来解决这个问题,但我不知道它是什么。