60

This might sound like a silly question but If you have a thirdParty.framework file, can you tell if it's static or dynamic? I mean, do they look different if you look inside?

2 Answers 2

138

It can be either.

Only iOS8+ will allow dynamic frameworks in the app bundle, however.

The way to find out is to look in the .framework and use the file command on the main file:

$ cd iOS/Crashlytics.framework
$ ls -l
total 9984
-rwxr-xr-x  1 andy  staff  4710656 11 Sep 17:11 Crashlytics
drwxr-xr-x  8 andy  staff      272 11 Sep 17:11 Headers
-rw-r--r--  1 andy  staff     1553 11 Sep 17:11 Info.plist
drwxr-xr-x  3 andy  staff      102 11 Sep 17:11 Modules
-rwxr-xr-x  1 andy  staff   146164 11 Sep 17:11 run
-rwxr-xr-x  1 andy  staff   241688 11 Sep 17:11 submit
$ file Crashlytics 
Crashlytics: Mach-O universal binary with 5 architectures
Crashlytics (for architecture armv7):   current ar archive random library
Crashlytics (for architecture armv7s):  current ar archive random library
Crashlytics (for architecture i386):    current ar archive random library
Crashlytics (for architecture x86_64):  current ar archive random library
Crashlytics (for architecture arm64):   current ar archive random library

Where ar archive means "static library".

Alternatively, a "dynamic" framework will look like this and explicitly state that it's dynamically linked.

$ cd /Library/Frameworks/iTunesLibrary.framework/
$ ls -l
total 40
lrwxr-xr-x  1 root  wheel   24 10 Sep 17:38 Headers -> Versions/Current/Headers
lrwxr-xr-x  1 root  wheel   24 10 Sep 17:38 Modules -> Versions/Current/Modules
lrwxr-xr-x  1 root  wheel   26 10 Sep 17:38 Resources -> Versions/Current/Resources
drwxr-xr-x  4 root  wheel  136 10 Sep 17:41 Versions
lrwxr-xr-x  1 root  wheel   22 10 Sep 17:38 XPCServices -> Versions/A/XPCServices
lrwxr-xr-x  1 root  wheel   30 10 Sep 17:38 iTunesLibrary -> Versions/Current/iTunesLibrary
$ file Versions/Current/iTunesLibrary 
Versions/Current/iTunesLibrary: Mach-O universal binary with 2 architectures
Versions/Current/iTunesLibrary (for architecture i386): Mach-O dynamically linked shared library i386
Versions/Current/iTunesLibrary (for architecture x86_64):   Mach-O 64-bit dynamically linked shared library x86_64
3
  • Could you please elaborate more about "use the file command on the main file"? should i call in the terminal? Sep 15, 2015 at 17:21
  • When linking a dynamic framework into your app, do you need to use Embedded Library? I am getting a runtime error at startup dyld __abort_with_payload that implies the library isn't linked correctly. Confusingly though, if I put it in Embedded Library, it works, but if I immediately take it out again, it still works. Something subtle that I don't understand is happening.
    – Jim Leask
    May 3, 2017 at 14:56
  • 1
    Could you clarify what the second terminal session is showing? I'm assuming that is showing a dynamic framework's output, but it isn't explicitly stated anywhere in the answer.
    – Adam Johns
    Nov 8, 2017 at 22:16
14

I use this command to list all STATIC Frameworks from a path with a list of frameworks:

find -E . -type f -iregex ".*\.framework\/[^./]*" -exec file {} \; | grep ': current ar archive' | sed 's/.*\/\(.*.framework\).*/\1/'
2
  • 1
    Thnx 💪 Removed the : before current ar archive to make it work. Terminal outputs with tabs, which to not carry well to copy/paste stuff on websites.
    – Stijn
    Sep 1, 2020 at 13:14
  • Which directory level should I be running this?
    – Hlung
    Mar 26, 2021 at 5:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.