objective c - What is the best way to avoid duplicate symbols in project that will use my iOS framework and one of the dependencies? -


here quotation other post:

i'm working in ios project includes static library created company. library include old version of afneworking , don't have source files.

now need use more recent (and less bugged) version of afneworking, cannot include same class twice in project (of course) because "duplicate symbols"

my problem i'm preparing ios framework , i want avoid kind of situation in future. i'm not talking afnetworking, other quite popular ios framework. in addition applied custom changes in original framework code.

the 1 way avoid "duplicate symbols" , "class x implemented in both y , z. 1 of 2 used" comes mind add prefix original framework classes, right solution?

update 1:

i tried apply john's solution no joy. have created simplified project (here link repo) 2 classes frameworkclass present in framework target only, , sharedclass present in both framework , application targets, maybe can see if i'm doing wrong. after application did launch i'm still getting: objc[96426]: class sharedclass implemented in both .../testframework.framework/testframework , .../symbolsvisibilitytest.app/symbolsvisibilitytest. 1 of 2 used. 1 undefined

update 2:

here output nm based on provided sample project's framework-output:

0000000000007e14 t -[frameworkclass doframework] 0000000000007e68 t -[sharedclass doshared]                  u _nslog                  u _nsstringfromselector 00000000000081f0 s _objc_class_$_frameworkclass                  u _objc_class_$_nsobject 0000000000008240 s _objc_class_$_sharedclass 00000000000081c8 s _objc_metaclass_$_frameworkclass                  u _objc_metaclass_$_nsobject 0000000000008218 s _objc_metaclass_$_sharedclass 0000000000007fb0 s _testframeworkversionnumber 0000000000007f70 s _testframeworkversionstring                  u ___cfconstantstringclassreference                  u __objc_empty_cache                  u _objc_release                  u _objc_retainautoreleasedreturnvalue                  u dyld_stub_binder` 

update 3:

i did manage "hide" sharedclass symbols applying the solution @bleater , output nm now:

         u _nslog          u _nsstringfromselector 00001114 s _objc_class_$_frameworkclass          u _objc_class_$_nsobject 00001100 s _objc_metaclass_$_frameworkclass          u _objc_metaclass_$_nsobject          u ___cfconstantstringclassreference          u __objc_empty_cache          u _objc_release          u _objc_retainautoreleasedreturnvalue          u dyld_stub_binder` 

but i'm still getting double implementation warning in xcode.

you should limit visibility of symbols in framework or library developing. set default visibility hidden, , explicitly mark functions in public interface visible.

this avoids problems have described. can include version of public library (afnetworking, sqlite, etc.), without fear of future conflict because linking framework or library won't able "see" symbols.

to set default visibility hidden can go project settings , set "symbols hidden default" yes. set no unless change it.

enter image description here

there @ least couple of ways mark symbols public interface "visible". 1 using exports file, go through , explicitly mark functions visible:

#define export __attribute__((visibility("default"))) export int myfunction1(); 

the define convenience. define export once , add export of public symbols.

you can find official apple documentation on here:

runtime environment programming guide

update:

i took @ sample project, , looks pointed in wrong direction. appears can hide c , c++ symbols. if having problem c lib (like sqlite), setting default visibility hidden work. looks nature of objective c runtime prevents making symbols invisible. can mark visibility on these symbols, objective-c appears way have linker enforce should or shouldn't able use library (while still leaving them visible).

so if redefine objective-c symbol in different compilation unit same name (by perhaps compiling in new version of popular open source library), still have conflict.

i think solution @ point first suggested , prefix symbols including framework unique identifier. isn't elegant solution, limits of objective c runtime believe best solution available.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -