Search code examples
iosobjective-cxcodestatic-librariesduplicate-symbol

iOS duplicate symbols from different versions of the same library


App A requires third-party libraries B and C. Both B and C include different versions of library D (from a further third-party). No third-party source code is available. This will give duplicate symbol errors when linking the app.

What solutions are available?


Related question involving identical libraries, allowing one copy to simply be deleted: How to handle duplicate symbol error from 3rd party libraries?


Solution

  • This was solved by renaming the conflicting symbols in B (and its version of D if separate). This can be done directly on the binary as long as the renames are the same length as the originals (e.g. by reversing the library prefix).

    local $/ = "\0";
    open my $fh, '<+', $library;
    binmode $fh;
    
    while (my $field = <$fh>) {
        my $length = length $field;
        chomp $field;
    
        if (defined $translation{$field}) {
            seek $fh, -$length, SEEK_CUR;
            print $fh $translation{$field};
        }
    }