1 <!-- ##### SECTION Title ##### -->
2 Dynamic Loading of Modules
4 <!-- ##### SECTION Short_Description ##### -->
5 portable method for dynamically loading 'plug-ins'.
7 <!-- ##### SECTION Long_Description ##### -->
9 These functions provide a portable way to dynamically load object files
10 (commonly known as 'plug-ins').
11 The current implementation supports all systems that provide
12 an implementation of dlopen() (e.g. Linux/Sun), as well as HP-UX via its
13 shl_load() mechanism, and Windows platforms via DLLs.
17 A program, which wants to use these functions must be linked to the
18 libraries output by the command "glib-config --libs gmodule".
22 To use them you must first determine whether dynamic loading
23 is supported on the platform by calling g_module_supported().
24 If it is, you can open a module with g_module_open(),
25 find the module's symbols (e.g. function names) with g_module_symbol(),
26 and later close the module with g_module_close().
27 g_module_name() will return the file name of a currently opened module.
30 If any of the above functions fail, the error status can be found with
34 The gmodule implementation features reference counting for opened modules,
35 and supports hook functions within a module which are called when the
36 module is loaded and unloaded (see #GModuleCheckInit and #GModuleUnload).
39 If your module introduces static data to common subsystems in the running
40 program, e.g. through calling g_quark_from_static_string ("my-module-stuff"),
41 it must ensure that it is never unloaded, by calling g_module_make_resident().
44 <!-- ##### SECTION See_Also ##### -->
49 <!-- ##### STRUCT GModule ##### -->
51 The #GModule struct is an opaque data structure to represent a
52 <link linkend="glib-Dynamic-Loading-of-Modules">Dynamically-Loaded Module</link>.
53 It should only be accessed via the following functions.
57 <!-- ##### FUNCTION g_module_supported ##### -->
59 Checks if modules are supported on the current platform.
62 @Returns: TRUE if modules are supported.
65 <!-- ##### FUNCTION g_module_build_path ##### -->
67 A portable way to build the filename of a module. The platform-specific
68 prefix and suffix are added to the filename, if needed, and the result is
69 added to the directory, using the correct separator character.
72 The directory should specify the directory where the module can be found.
73 It can be NULL or an empty string to indicate that the module is in a standard
74 operating-system specific directory, though this is not recommended since the
75 wrong module may be found.
78 For example, calling g_module_build_path() on a Linux system with a directory
79 of "/lib" and a module_name of "mylibrary" will return "/lib/libmylibrary.so".
80 On a Windows system, using "\Windows" as the directory it will return
81 "\Windows\mylibrary.dll".
84 @directory: the directory where the module is. This can be NULL or the empty
85 string to indicate that the standard operating system-specific directories
86 will be used, though that is not recommended.
87 @module_name: the name of the module.
88 @Returns: the complete path of the module, including the standard library
89 prefix and suffix. This should be freed when no longer needed.
92 <!-- ##### FUNCTION g_module_open ##### -->
94 Opens a module. If the module has already been opened, its reference
99 First of all g_module_open() tries to open @file_name as a module. If
100 that fails and @file_name has the ".la"-suffix (and is a libtool
101 archive) it tries to open the corresponding module. If that fails and
102 it doesn't have the proper module suffix for that plaform
103 (#G_MODULE_SUFFIX,) this suffix will be appended and the coresponding
104 module will be opended. If that fails and @file_name doesn't have the
105 ".la"-suffix, this suffix is appended and g_module_open() tries to
106 open the corresponding module. If eventually that fails as well, NULL
110 @file_name: the name of the file containing the module.
111 @flags: the flags used for opening the module. Currently this can be 0 or
112 G_MODULE_BIND_LAZY for lazy binding, where symbols are only bound when needed.
113 @Returns: a #GModule on success, or NULL on failure.
116 <!-- ##### ENUM GModuleFlags ##### -->
118 Flags passed to g_module_open().
119 G_MODULE_BIND_LAZY specifies that symbols are only resolved when needed.
120 The default action is to bind all symbols when the module is loaded.
121 (G_MODULE_BIND_LAZY is not supported on all platforms.)
127 <!-- ##### FUNCTION g_module_symbol ##### -->
129 Gets a symbol pointer from a module.
133 @symbol_name: the name of the symbol to find.
134 @symbol: returns the pointer to the symbol value.
135 @Returns: TRUE on success.
138 <!-- ##### FUNCTION g_module_name ##### -->
140 Gets the file name from a #GModule.
144 @Returns: the file name of the module, or "main" if the module is the main
148 <!-- ##### FUNCTION g_module_make_resident ##### -->
150 Ensures that a module will never be unloaded.
151 Any future g_module_close() calls on the module will be ignored.
154 @module: a module to make permanently resident.
157 <!-- ##### FUNCTION g_module_close ##### -->
162 @module: the module to close.
163 @Returns: TRUE on success.
166 <!-- ##### FUNCTION g_module_error ##### -->
168 Gets a string describing the last module error.
171 @Returns: a string describing the last module error.
174 <!-- ##### USER_FUNCTION GModuleCheckInit ##### -->
176 Specifies the type of the module initialization function.
177 If a module contains a function named g_module_check_init() it is called
178 automatically when the module is loaded. It is passed the #GModule structure
179 and should return NULL on success or a string describing the initialization
183 @module: the #GModule corresponding to the module which has just been loaded.
184 @Returns: NULL on success, or a string describing the initialization error.
187 <!-- ##### USER_FUNCTION GModuleUnload ##### -->
189 Specifies the type of the module function called when it is unloaded.
190 If a module contains a function named g_module_unload() it is called
191 automatically when the module is unloaded.
192 It is passed the #GModule structure.
195 @module: the module about to be unloaded.
198 <!-- ##### MACRO G_MODULE_EXPORT ##### -->
200 Used to declare functions exported by modules.
205 <!-- ##### MACRO G_MODULE_IMPORT ##### -->
207 Used to declare functions imported from modules.