package core:dynlib

⌘K
Ctrl+K
or
/

    Overview

    Package core:dynlib implements loading of shared libraries/DLLs and their symbols.

    The behaviour of dynamically loaded libraries is specific to the target platform of the program. For in depth detail on the underlying behaviour please refer to your target platform's documentation.

    Index

    Types (1)
    Constants (0)

    This section is empty.

    Variables (0)

    This section is empty.

    Procedure Groups (0)

    This section is empty.

    Types

    Library ¶

    Library :: distinct rawptr
     

    A handle to a dynamically loaded library.

    Related Procedures With Parameters
    Related Procedures With Returns

    Constants

    This section is empty.

    Variables

    This section is empty.

    Procedures

    load_library ¶

    load_library :: proc(path: string, global_symbols: bool = false) -> (library: Library, did_load: bool) {…}
     

    Loads a dynamic library from the filesystem. The paramater global_symbols makes the symbols in the loaded library available to resolve references in subsequently loaded libraries.

    The paramater global_symbols is only used for the platforms linux, darwin, freebsd and openbsd. On windows this paramater is ignored.

    The underlying behaviour is platform specific.
    On linux, darwin, freebsd and openbsd refer to dlopen.
    On windows refer to LoadLibraryW.

    Implicit Allocators
    context.temp_allocator

    Example:
    import "core:dynlib"
    import "core:fmt"
    
    load_my_library :: proc() {
    	LIBRARY_PATH :: "my_library.dll"
    	library, ok := dynlib.load_library(LIBRARY_PATH)
    	if ! ok {
    		return
    	}
    	fmt.println("The library %q was successfully loaded", LIBRARY_PATH)
    }
    

    symbol_address ¶

    symbol_address :: proc(library: Library, symbol: string) -> (ptr: rawptr, found: bool) #optional_ok {…}
     

    Loads the address of a procedure/variable from a dynamic library.

    The underlying behaviour is platform specific.
    On linux, darwin, freebsd and openbsd refer to dlsym.
    On windows refer to GetProcAddress.

    Implicit Allocators
    context.temp_allocator

    Example:
    import "core:dynlib"
    import "core:fmt"
    
    find_a_in_my_library :: proc() {
    	LIBRARY_PATH :: "my_library.dll"
    	library, ok := dynlib.load_library(LIBRARY_PATH)
    	if ! ok {
    		return
    	}
    
    	a, found_a := dynlib.symbol_address(library, "a")
    	if found_a do fmt.printf("The symbol %q was found at the address %v", "a", a)
    }
    

    unload_library ¶

    unload_library :: proc(library: Library) -> (did_unload: bool) {…}
     

    Unloads a dynamic library.

    The underlying behaviour is platform specific.
    On linux, darwin, freebsd and openbsd refer to dlclose.
    On windows refer to FreeLibrary.

    Example:
    import "core:dynlib"
    import "core:fmt"
    
    load_then_unload_my_library :: proc() {
    	LIBRARY_PATH :: "my_library.dll"
    	library, ok := dynlib.load_library(LIBRARY_PATH)
    	if ! ok {
    		return
    	}
    	did_unload := dynlib.unload_library(library)
    	if ! did_unload {
    		return
    	}
    	fmt.println("The library %q was successfully unloaded", LIBRARY_PATH)
    }
    

    Procedure Groups

    This section is empty.

    Source Files

    Generation Information

    Generated with odin version dev-2023-10 (vendor "odin") Windows_amd64 @ 2023-10-03 21:09:46.661201700 +0000 UTC