Question

I have a hard time grasping the concept of dylibs.

I am currently developing a cross-platform game in C++ using multiple external dylibs. With the CMake GUI on OSX, I built almost all my dependencies for my program including Box2D, SFML, Thor and CEGUI(In progress) and placed them in specific folders on my desktop. Since I am unfamiliar with these libraries, I created a test project that includes all my dependencies with the soul objectif to verify if my dylibs work.

This is what I understand about dylibs :

  • Dylibs need to be inside your app bundle in the Frameworks folder.

  • They need to be linked into your project via the build settings in XCode.

  • Dylibs helps reduce the size of the app compared to static libraries.

With that in mind, I played with the settings and build phases for my test project and created a script for each dependency that will copy the dylibs from my desktop into the Frameworks folder of my app bundle every time i build the project.

The app, including all its features from the external libraries, work.

The only thing I do not understand about this, is how do dylibs "reduce the size of the app" if i need to copy all of them into my app bundle? I am guessing that if were to run my test app on a different computer, it would probably work because everything is in the app bundle. But isn't that contradictory to the goal of dylibs?

Here is a link to the Dynamic Library Programming Documentation of Apple that i have consulted.

Was it helpful?

Solution

looking at you main points

Dylibs need to be inside your app bundle in the Frameworks folder.

No they do not they can go in a common place like /Library/Frameworks. If there they can be used by more than one application

They need to be linked into your project via the build settings in XCode.

Yes

Dylibs helps reduce the size of the app compared to static libraries.

That is not what the document says. It says

Using dynamic libraries instead of static libraries reduces the executable file size of an app.

Thus the size of the executable file (not application bundle) is reduced. If you have put a dynamic libary in /Library/Frameworks or similar then share it between two applications then the overal size on the disk of those apps will be less than if you had used static libraries.

In general if you are releasing via the AppStore or similar and just run the .app and have no sub processes then there is no size benefit but you still get the other benefits of delay loading etc. If however you do run a subprocess from the main app then you can share code in the dynamic library, saving memory space as well as explained in Apple's document.

If you install via an installer you can place the Frameworks where that can be shared amd used by other apps. e.g. If you have two apps and they have common code you can put that in a shared place.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top