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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With