Skip to content

dl #


dl can be used to Dynamically Load a library during runtime. It is a thin wrapper over LoadLibrary on Windows, and dlopen on Unix.

Using it, you can implement a plugin system for your application.

Note We highly recommend using dl.loader instead of dl directly. It provides a more user-friendly API in the V way.

Constants #

const version = 1
const dl_ext = get_shared_library_extension()
const rtld_next = voidptr(-1)
const (
	rtld_now      = C.RTLD_NOW
	rtld_lazy     = C.RTLD_LAZY
	rtld_global   = C.RTLD_GLOBAL
	rtld_local    = C.RTLD_LOCAL
	rtld_nodelete = C.RTLD_NODELETE
	rtld_noload   = C.RTLD_NOLOAD

fn close #

fn close(handle voidptr) bool

close frees a given shared object.

fn dlerror #

fn dlerror() string

dlerror provides a text error diagnostic message for functions in dl it returns a human-readable string, describing the most recent error that occurred from a call to one of the dl functions, since the last call to dlerror()

fn get_libname #

fn get_libname(libname string) string

get_libname returns a library name with the operating system specific extension for shared libraries.

fn get_shared_library_extension #

fn get_shared_library_extension() string

get_shared_library_extension returns the platform dependent shared library extension i.e. .dll on windows, .so on most unixes, .dylib on macos.

fn open #

fn open(filename string, flags int) voidptr

open loads the dynamic shared object.

fn open_opt #

fn open_opt(filename string, flags int) !voidptr

open_opt - loads the dynamic shared object.
Unlike open, open_opt return an option.

fn sym #

fn sym(handle voidptr, symbol string) voidptr

sym returns an address of a symbol in a given shared object.

fn sym_opt #

fn sym_opt(shared_object_handle voidptr, symbol string) !voidptr

sym_opt returns the address of a symbol in a given shared object, if found.
Unlike sym, sym_opt returns an option.