Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I solve class name conflicts when creating an iOS framework?

I am writing an iOS framework Foo that depends on a static third-party library Lib and have problems getting the linking right.

If Foo was a static library, I would not link it against Lib, and only link the master project against both of them. But this approach does not seem to work with a framework: the linker complains about missing symbols from Lib.

So I took the other approach and linked Foo against Lib. Now the linker is happy, but there’s an obvious catch: if the master project uses Lib for its own reasons and links both against Foo and Lib, I get duplicate symbols:

Class <Something> is implemented in both <Here> and <There>.
One of the two will be used. Which one is undefined.

I know I can stop linking the app against Lib and all will be fine, but I’d like to get things right. How?

like image 351
zoul Avatar asked Jun 17 '14 13:06

zoul


1 Answers

I was able to get this working for a framework, though the docs say it should work for a static library as well.

What I did is link the master project against both Foo and Lib as you say. Now Foo has "missing symbol" errors. Select the Foo target and go to Other Linker Flags. Add -weak_framework Lib and presto! the linker will stop complaining. The duplicate symbol runtime errors go away.

According to the docs:

The -weak_framework option tells the linker to weakly link all symbols in the named framework. If you need to link to a library instead of a framework, you can use the -weak_library linker command instead

like image 126
bcattle Avatar answered Nov 15 '22 01:11

bcattle