How To Load Libraries Mac

The Library Manager is the simplest and safest way to install libraries. If possible, that is the method you should use. If the library you want to use is not available via the library manager, you can get the source code and place it into your machine's local library folder. The location of the folder is rather specific. Mac OS X: Accessing Hidden Library Folders 1 1 1 1 1 Rating 3.10 (21 Votes) In this Tip's N Tricks article, I want to point out a very important tip for getting around one of Apple's more peculiar security precautions in Mac OS X Lion and Mountain Lion.

Once your framework is ready to go, you need to decide where to install it. Where you install a framework also helps determine how to install the framework.

Locations for Public Frameworks

How To Load Libraries Mac

Third-party frameworks can go in a number of different file-system locations, depending on certain factors.

  • Most public frameworks should be installed at the local level in /Library/Frameworks.

  • If your framework should only be used by a single user, you can install it in the ~/Library/Frameworks subdirectory of the current user; however, this option should be avoided if possible.

  • If they are to be used across a local area network, they can be installed in /Network/Library/Frameworks; however, this option should be avoided if possible.

How To Load Libraries Machine

For nearly all cases, installing your frameworks in /Library/Frameworks is the best choice. Frameworks in this location are discovered automatically by the compiler at compile time and the dynamic linker at runtime. Applications that link to frameworks in other directories, such as ~/Library/Frameworks or /Network/Library/Frameworks, must specify the exact path to the framework at build time so that the dynamic linker can find it. If the path changes (as it might for a user home directory), the dynamic linker may be unable to find the framework.

Another reason to avoid installing frameworks in ~/Library/Frameworks or /Network/Library/Frameworks is the potential performance penalties. Frameworks installed in network directories or in network-based user home directories can cause significant delays in compilation times. Loading the framework across the network can also slow down the launch of the target application.

Third-party frameworks should never be installed in the /System/Library/Frameworks directory. Access to this directory is restricted and is reserved for Apple-provided frameworks only.

When you build an application or other executable, the compiler looks for frameworks in/System/Library/Frameworks as well as any other location specified to the compiler. The compiler writes path information for any required frameworks in the executable file itself, along with version information for each framework. When the application is run, the dynamic link editor tries to find a suitable version of each framework using the paths in the executable file. If it cannot find a suitable framework in the specified location (perhaps because it was moved or deleted), it looks for frameworks in the following locations, in this order:

  1. The explicit path to the framework that was specified at link time.

  2. The /Library/Frameworks directory.

  3. The /System/Library/Frameworks directory.

If the dynamic link editor cannot locate a required framework, it generates a link edit error, which terminates the application.

Locations for Private Frameworks

Custom frameworks intended for internal use should be installed inside the application that uses them. Frameworks embedded in an application are stored in the Frameworks directory of the application bundle. The advantage of embedding frameworks in this manner is that it guarantees the application always has the correct version of the framework to run against. See Embedding a Private Framework in Your Application Bundle for information on how to embed a custom framework in your application.

The limitation of embedding frameworks is that you cannot share the framework among a suite of applications. If your company develops a suite of applications that rely on the same framework, you might want to install one copy of that framework that all of the applications can share. In such a situation, you should install the frameworks in the /Library/Frameworks directory and make sure the frameworks bundle does not contain any public header information.

Installing Frameworks

How you install frameworks depends on your framework. If your framework is bundled inside of a particular application, there is nothing special you need to do. The user can drag the application bundle to a local system and use the application without any need for additional installation steps.

(I suspect that any Mac over five years old hates me, but I can’t prove that.) However, if this problem is happening to you and Apple’s permissions solution doesn’t fix it, I’d suggest. Mar 24, 2020  Reset permissions. Turn on or restart your Mac, then immediately press and hold Command (⌘)-R to start up from macOS Recovery. You might be prompted to enter a password, such as a firmware password or the password of a user who is an administrator of this Mac. When you see the macOS. Fix At the bottom of the window, you’ll see an area labeled Reset Home Directory Permissions and ACLs. Click the Reset button there. The reset process takes just a couple of minutes. When it’s done, exit the programs you’ve opened and restart your Mac. How to Fix Mac OS X File Permissions for the Entire Home Folder Restart the Mac into Mac OS X Recovery Mode by holding down Command-R as the Mac restarts. Open Terminal from the Utilities menu. Type the following command into terminal, all one word, and press the return key.

If your framework is external to an application, you should use an installation package to make sure it is put in the proper location. You should also use an installation package in situations where an older version of your framework might be in place. In that case, you might want to write some scripts to update an existing framework bundle rather than replace it entirely. For example, you may want to install a new major version of your framework without disturbing any other versions. Similarly, if you have multiple applications that rely on the same framework, your installation package should check for the existence of the framework and install it only as needed.

For more information on creating installation packages, see Distributing Apps Outside the Mac App Store.



Copyright © 2003, 2013 Apple Inc. All Rights Reserved. Terms of Use Privacy Policy Updated: 2013-09-17

Two important factors that determine the performance of apps are their launch times and their memory footprints. Reducing the size of an app’s executable file and minimizing its use of memory once it’s launched make the app launch faster and use less memory once it’s launched. Using dynamic libraries instead of static libraries reduces the executable file size of an app. They also allow apps to delay loading libraries with special functionality only when they’re needed instead of at launch time. This feature contributes further to reduced launch times and efficient memory use.

This article introduces dynamic libraries and shows how using dynamic libraries instead of static libraries reduces both the file size and initial memory footprint of the apps that use them. This article also provides an overview of the dynamic loader compatibility functions apps use to work with dynamic libraries at runtime.

What Are Dynamic Libraries?

Most of an app’s functionality is implemented in libraries of executable code. When an app is linked with a library using a static linker, the code that the app uses is copied to the generated executable file. A static linker collects compiled source code, known as object code, and library code into one executable file that is loaded into memory in its entirety at runtime. The kind of library that becomes part of an app’s executable file is known as a static library. Static libraries are collections or archives of object files.

Note: Static libraries are also known as static archive libraries and static linked shared libraries.

When an app is launched, the app’s code—which includes the code of the static libraries it was linked with—is loaded into the app’s address space. Linking many static libraries into an app produces large app executable files. Figure 1 shows the memory usage of an app that uses functionality implemented in static libraries. Applications with large executables suffer from slow launch times and large memory footprints. Also, when a static library is updated, its client apps don’t benefit from the improvements made to it. To gain access to the improved functionality, the app’s developer must link the app's object files with the new version of the library. And the apps users would have to replace their copy of the app with the latest version. Therefore, keeping an app up to date with the latest functionality provided by static libraries requires disruptive work by both developers and end users.

A better approach is for an app to load code into its address space when it’s actually needed, either at launch time or at runtime. The type of library that provides this flexibility is called dynamic library. Dynamic libraries are not statically linked into client apps; they don't become part of the executable file. Instead, dynamic libraries can be loaded (and linked) into an app either when the app is launched or as it runs.

Note: Dynamic libraries are also known as dynamic shared libraries, shared objects, or dynamically linked libraries.

Figure 2 shows how implementing some functionality as dynamic libraries instead of as static libraries reduces the memory used by the app after launch.

Using dynamic libraries, programs can benefit from improvements to the libraries they use automatically because their link to the libraries is dynamic, not static. That is, the functionality of the client apps can be improved and extended without requiring app developers to recompile the apps. Apps written for OS X benefit from this feature because all system libraries in OS X are dynamic libraries. This is how apps that use Carbon or Cocoa technologies benefit from improvements to OS X.

Another benefit dynamic libraries offer is that they can be initialized when they are loaded and can perform clean-up tasks when the client app terminates normally. Static libraries don’t have this feature. For details, see Module Initializers and Finalizers.

One issue that developers must keep in mind when developing dynamic libraries is maintaining compatibility with client apps as a library is updated. Because a library can be updated without the knowledge of the client-app’s developer, the app must be able to use the new version of the library without changes to its code. To that end, the library’s API should not change. However, there are times when improvements require API changes. In that case, the previous version of the library must remain in the user’s computer for the client app to run properly. Dynamic Library Design Guidelines explores the subject of managing compatibility with client apps as a dynamic library evolves.

How To Load Libraries To Arduino

How Dynamic Libraries Are Used

When an app is launched, the OS X kernel loads the app’s code and data into the address space of a new process. The kernel also loads the dynamic loader ( /usr/lib/dyld ) into the process and passes control to it. The dynamic loader then loads the app’s dependent libraries. These are the dynamic libraries the app was linked with. The static linker records the filenames of each of the dependent libraries at the time the app is linked. This filename is known as the dynamic library’s install name. The dynamic loader uses the app’s dependent libraries’ install names to locate them in the file system. If the dynamic loader doesn’t find all the app’s dependent libraries at launch time or if any of the libraries is not compatible with the app, the launch process is aborted. For more information on dependent-library compatibility, see Managing Client Compatibility With Dependent Libraries. Dynamic library developers can set a different install name for a library when they compile it using the gcc -install_name option. See the gcc man page for details.

The dynamic loader resolves only the undefined external symbols the app actually uses during the launch process. Other symbols remain unresolved until the app uses them. For details on the process the dynamic loader goes when an app is launched, see “Executing Mach-O Files” in Mach-O Programming Topics.

The dynamic loader—in addition to automatically loading dynamic libraries at launch time—loads dynamic libraries at runtime, at the app’s request. That is, if an app doesn't require that a dynamic library be loaded when it launches, developers can choose to not link the app’s object files with the dynamic library, and, instead, load the dynamic library only in the parts of the app that require it. Using dynamic libraries this way speeds up the launch process. Dynamic libraries loaded at runtime are known as dynamically loaded libraries. To load libraries at runtime, apps can use functions that interact with the dynamic loader for the platform under which they're running.

Note: The target architecture of the client and the dynamic library must be the same. Otherwise, the dynamic loader doesn’t load the library.

Different platforms implement their dynamic loaders differently. They may also have custom dynamic code-loading interfaces that make code difficult to port across platforms. To facilitate porting an app from UNIX to Linux, for example, Jorge Acereda and Peter O'Gorman developed the dynamic loader compatibility (DLC) functions. They offer developers a standard, portable way to use dynamic libraries in their apps.

The DLC functions are declared in /usr/include/dlfcn.h. There are five of them:

How To Load Libraries Mac
  • dlopen(3) OS X Developer Tools Manual Page: Opens a dynamic library. An app calls this function before using any of the library’s exported symbols. If the dynamic library hasn’t been opened by the current process, the library is loaded into the process’s address space. The function returns a handle that’s used to refer to the opened library in calls to dlsym and dlclose. This handle is known as the dynamic library handle. This function maintains a reference count that indicates the number of times the current process has used dlopen to open a particular dynamic library.

  • dlsym(3) OS X Developer Tools Manual Page: Returns the address of a symbol exported by a dynamically loaded library. An app calls this function after obtaining a handle to the library through a call to dlopen. The dlsym function takes as parameters the handle returned by dlopen or a constant specifying the symbol search scope and the symbol name.

  • dladdr(3) OS X Developer Tools Manual Page: Returns information on the address provided. If the address corresponds to a dynamically loaded library within the app’s address space, this function returns information on the address. This information is returned in a Dl_info structure, which encapsulates the pathname of the dynamic library, the library’s base address, and the address and value of the nearest symbol to the address provided. If no dynamic library is found at the address provided, the function returns no information.

  • dlclose(3) OS X Developer Tools Manual Page: Closes a dynamically loaded library. This function takes as a parameter a handle returned by dlopen. When the reference count for that handle reaches 0, the library is unloaded from the current process’s address space.

  • dlerror(3) OS X Developer Tools Manual Page: Returns a string that describes an error condition encountered by the last call to dlopen, dlsym, or dlclose.

For more information on the DLC functions, see OS X ABI Dynamic Loader Reference.



How To Load Libraries Mac Os

Copyright © 2012 Apple Inc. All Rights Reserved. Terms of Use Privacy Policy Updated: 2012-07-23