引用第三方库文件 duplicate symbol
When you link a static library that’s using ObjectiveC categories, you usually have instructions from the developers to add -ObjC and -all_load linker flags which solve linking problems and prevent crashes. Now, if you happen to have the same categories or other objc symbols in your project that uses this static library you’ll get linker errors for duplicate symbols. The most common example for this is using touch JSON framework. I have this static library that uses it, and I also use it in my own code. I’m running into this linking problem every once in a while so I’m going to explain it here and provide a solution for fixing/avoiding it.
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1
ld: duplicate symbol _OBJC_METACLASS_$_SBJSON in /Users/ivan/Projects/MyApp/sources/Trunk/MyApp/libtest-simulator.a(SBJSON.o) and /Users/ivan/Projects/MyApp/sources/Trunk/MyApp/build/MyApp.build/Debug-iphonesimulator/MyApp.build/Objects-normal/i386/SBJSON.o
WARNING: I’ll be talking about problems with touch JSON library because this is the common problem. Solutions may not apply to other libraries although the principle is more-less the same. Be warned.
Scenario #1
“My project uses 1 static library and both this library and my project need JSON framework”.
Simplest solution that might work is to remove -ObjC and -all_load linker flags. When I say ‘might’, I mean that you need to be extra careful with this. If you do this, the static library you link will depend on JSON code from your project so if there’s, for example, a version mismatch you’ll run into serious problems.
“My project uses a static library which depends on JSON framework but this library also links other ObjectiveC static libraries. Both my project and this static library need JSON framework”
OR
“I cannot remove -ObjC and -all_load because I need to properly link categories inside a static library, but I also need to add JSON framework to my own project”
Now this is a specific scenario I ran into earlier. I wanted to use Three20 library which links several different ObjC libraries of its own so I definitely need -ObjC and -all_load flags otherwise my app crashes. On the other hand, I had another static library which uses JSON framework and adding this framework to my project causes duplicate symbols linker error.
The solution is simple again but you also need to be extremely careful. You leave those linker flags to properly link ObjC libraries but you don’t add JSON framework in your project. Instead you depend on JSON library linked with the static library you are using. You will, however, need to add header files in order to avoid compilation errors in your own code. Possible problem here is header files vs. compiled code in the static library mismatch. So you need to make sure that the JSON header files you’re using match the JSON code version linked with the static library. If you already imported JSON framework, just remove .m files in XCode from your target.
JSON framework xcode
JSON framework files
Bottomline
Obviously, these are some rare cases of linking problems however, JSON touch framework is a very popular framework and it’s not uncommon that some 3rd party libraries you want to use are built on top of it. My final advice is to understand the problem and why it happens, then you will be able to solve it one way or the other. Good luck!
分享到:
相关推荐
### Altium Designer中“Duplicate Net Names Wire”错误的终极解决办法 #### 一、问题概述 在使用Altium Designer进行电路设计过程中,遇到“Duplicate Net Names Wire”这一类错误是较为常见的现象。这类错误通常...
Duplicate File Cleaner是一款功能强大的重复文件清理工具,它能够帮助用户扫描并识别计算机上所有重复的文件,从而节省磁盘空间,提升系统性能。 ### 软件概述 Duplicate File Cleaner的主要功能包括但不限于: ...
### ORACLE RMAN DUPLICATE 数据库复制详解 #### 概述 在Oracle环境中,通过RMAN(Recovery Manager)工具可以高效地复制整个数据库。本文将详细介绍如何利用RMAN的`DUPLICATE`命令来实现数据库的复制,并针对两种...
FirmTools Duplicate Photo Finder是一款整理图像的必备工具,它使用高级搜索算法,会快速在您的硬盘或指定文件夹中找到重复或相似的图像,需要的朋友快来下载吧。 FirmTools Duplicate PhotoFinder 使用了先进的...
duplicate cleaner pro 破解版 4.0.5 。安装后,将第二步的x86及x64目录下的文件拷贝到安装目录下的x86与x64下。然后启动,输入长一点的序列号(随便输入字符),即可破解。
FirmTools Duplicate Photo Finder 相似图像查询软件 你电脑中如果有很多图像,有很多可能是一个logo只差,你用其他md5检测软件是不能快速找出来的。这个软件可以搜索相似的图像,你查看后选择删除,非常的方便。 ...
Oracle 11gR2 使用 RMAN duplicate from active database 复制数据库 Oracle 11gR2 中使用 RMAN duplicate from active database 复制数据库是一种高效的数据库复制方法。这种方法可以直接从活动数据库复制,省去...
Duplicate File Finder单文件
Outlook Duplicate Items Remover是一款专为Microsoft Outlook设计的工具,旨在帮助用户解决电子邮件、联系人、日历项、任务和笔记等重复数据的问题。在Outlook中,由于各种原因(如手动复制、同步错误或软件故障)...
Duplicate cleaner pro v3.2.7crack
### Oracle DataGuard 环境搭建详解:使用Duplicate方法 #### 一、Oracle DataGuard简介与应用场景 Oracle DataGuard是一种高可用性和灾难恢复解决方案,它能够保护数据免受逻辑和物理故障的影响。DataGuard通过...
### Oracle RMAN DUPLICATE 教程详解 #### 一、RMAN Duplicate 概述 **RMAN (Recovery Manager)** 是 Oracle 数据库管理系统中的一个重要工具,用于管理数据库的备份、恢复以及灾难恢复策略。其中,**Duplicate** ...
《Duplicate Cleaner Pro:高效精准的文件去重利器》 在我们的日常工作中,无论是个人电脑还是企业服务器,都可能面临文件堆积、重复数据占用大量存储空间的问题。这时,一款高效的文件去重工具就显得尤为重要。...
碰到了 #1062 – Duplicate entry ‘1′ for key ‘PRIMARY’ 当时那个急啊,原本的数据我已经全部删除了,没办法只有请求万能的百度了。我找了大半天终于给我给我找到了。兴奋ing,马上测试,O(∩_∩)O哈哈~成功了...
面对众多的重复邮件,如何可以快速地删除重复邮件,Outlook Duplicate Items Remover ,快速,简单
Duplicate Cleaner Pro 5.19.0.0_中文直装版文件查重神器
Duplicate File Finder 3.5 完整汉化版 Duplicate File Finder 可以找出硬盘上一个或者多个目录中的重复文件。Duplicate File Finder 不象某些程序仅仅是检查文件名,它检查文件的二进位内容而不理会文件名。可以...
以下是使用RMAN通过`duplicate`命令创建备用数据库的详细步骤和知识点: 1. **环境准备**: 在进行任何操作之前,确认主数据库处于归档模式。如描述中所示,可以通过`archive log list`命令查看数据库是否已启用...
【Duplicate Cleaner v2.04】是一款高效实用的免费软件,专为用户解决电脑中重复文件堆积的问题。这款工具能够帮助用户快速扫描、识别并删除重复的文件,从而释放宝贵的磁盘空间,优化电脑性能。 在当今数字时代,...
maya路径复制mel脚本 path_duplicate.mel