For another universal library I need to combine 2 existing dylibs (here x86 and x64) into a single universal lib. How can I do that without re-building the existing libraries?
Asked
Active
Viewed 3,874 times
13
-
@trojanfoe: Can you elaborate a little? Won't libtool work? – Toastor Apr 01 '14 at 11:10
-
No, it's the same a decomposing a binary executable. Once the linker has done its work, relocating, dumping unused functions, etc, it's very difficult (impossible?) to get it back to something you can re-link. The only real option is to have the object files and create the `.dylib` using them. However it's not clear why having 2 `.dylib`s is such a big deal in the first place... – trojanfoe Apr 01 '14 at 11:12
-
@trojanfoe The reasons for combining dylibs set aside - shouldn't it be possible (in theory) to just append one dylib to the other and to merge the symbol tables (applying offsets to the symbols)? I have only a basic understanding of how dylibs are structured, so forgive me if I sound silly. I'm here to learn :) – Toastor Apr 01 '14 at 11:57
-
I *very* much doubt it. The tools just don't exist to do this as there is (normally) no need for it. – trojanfoe Apr 01 '14 at 12:20
-
@trojanfoe yes, I'm aware that there probably are no such tools. I meant to ask if it is possible in theory - if one would be able to create such a tool, disregarding whether that would actually make any sense. I'm just trying to expand my understanding of the inner workings of libraries and frameworks currently. Can you recommend some good reading on the matter? – Toastor Apr 01 '14 at 12:36
-
Start here I guess: https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/000-Introduction/Introduction.html#//apple_ref/doc/uid/TP40001908-SW1 – trojanfoe Apr 01 '14 at 12:51
-
@trojanfoe Was looking for something more about the inner workings, less about usage. But never mind, we're getting too off-topic here I think. Will keep looking... Thanks anyway – Toastor Apr 02 '14 at 08:17
1 Answers
25
Actually, it's extremely easy to do once you know it. There's a tool called lipo that can do a number of things with dylibs. One is to combine two (or more) libraries. For example:
lipo lib1.dylib lib2.dylib -output combined.dylib -create
where lib1 could be an i386 and lib2 an x86_64 arch type. It will create a dylib in the local folder containing both archs.

Mike Lischke
- 48,925
- 16
- 119
- 181