3、Dependent libraries are loaded into the same process the client is being loaded into as part of its load process. For example, when an app is launched, its dependent libraries are loaded as part of the launch process, before the main function is executed.
The compiler -weak_library command-line option: This option tells the compiler to treat all the library’s exported symbols as weakly linked symbols.
- static, but the static storage class is not appropriate to hide symbols from the client but disclose them to all the library’s modules.
- export_list, before adding symbol _
- set the visibility attribute in their implementations to "default" and set the -fvisibility compiler command-line option to hidden when compiling the library’s source files.
/* File: Person.c */
#include "Person.h" #include <string.h>
// Symbolic name for visibility("default") attribute. #define EXPORT __attribute__((visibility("default"))) // 在源文件使用
char _person_name[30] = {'\0'};
EXPORT // Symbol to export char* name(void) {
return _person_name; }
void _set_name(char* name) {
strcpy(_person_name, name);
EXPORT // Symbol to export void set_name(char* name) {
if (name == NULL) {
_set_name("");
}
- Executable-relative location, @executable_path
- Library-relative location, @loader_path
-
The +load method: Initializes resources needed by a class or a category. The Objective-C runtime sends the load message to every class a library implements; it then sends the load message to every category the library implements.
-
Module initializers: Initializes a module. The dynamic loader calls all the initializer functions (defined with the constructor attribute) in each of a library’s modules.
dependent library 在main之前加载,故在main之前调用initializer,并在main结束之后调用finitializerruntime load library在main之后加载,故在main之后调用initializer,且 在main结束之后调用finitializer -
The +initialize method:
-
The Objective-C runtime sends the initialize message to a class just before creating an instance of the class.
/* File: Person.h */
#define WEAK_IMPORT __attribute__((weak_import)) // 在头文件中使用
WEAK_IMPORT void clear_name(void);
The dependent library loads successfully whether or not it implements clear_name. But it doesn’t load if it doesn’t define either name or set_name.
16、
The standard locations for header files are ~/include, /usr/local/include and /usr/include. The standard locations for dynamic libraries are ~/lib, /usr/local/lib, and /usr/lib
dynamic labrary 非标准路径安装相关环境变量
LD_LIBRARY_PATH
DYLD_LIBRARY_PATH
DYLD_FALLBACK_LIBRARY_PATH
17、Environment variables that effect dynamic loader logging
Environment variable |
Description |
|
Logs when images are loaded. |
DYLD_PRINT_LIBRARIES_POST_- LAUNCH |
Logs when images are loaded as a result of a dlopen call. Includes a dynamic libraries’ dependent libraries. |
|
Logs the invocation that causes the dynamic loader to return the address of a symbol. |
|
Logs statistical information on an application’s launch process, such as how many images were loaded, when the application finishes launching. |
|
Logs when the dynamic loader calls initializer and finalizer functions. |
|
Logs when the dynamic loader maps a segment of a dynamic library to the current process’s address space. |
|
Logs when the dynamic loader binds an undefined external symbol with its definition. |
Reproduced in: https: //my.oschina.net/dake/blog/196717