Skip to content

dl #

Description

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.

A V shared library can return interface values whose concrete types exist only inside that library. Their methods can be called by a program that loaded the library with dl.open (or dl.loader), as long as it has not been closed yet.

Private Boehm collectors in V shared libraries use one marking thread, so parallel marker workers cannot outlive the loaded image. An initialized host collector retains its marking policy.

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)

Available on Unix only.

const rtld_now = C.RTLD_NOW
const rtld_lazy = C.RTLD_LAZY
const rtld_global = C.RTLD_GLOBAL
const rtld_local = C.RTLD_LOCAL
const rtld_nodelete = C.RTLD_NODELETE
const rtld_noload = C.RTLD_NOLOAD

Available on Windows only.

const rtld_now = 0
const rtld_lazy = 0
const rtld_global = 0
const rtld_local = 0
const rtld_nodelete = 0
const rtld_noload = 0

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 #

@[inline]
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 #

@[inline]
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 a given dynamic shared object.

fn open_opt #

fn open_opt(filename string, flags int) !voidptr

open_opt tries to load a given dynamic shared object.

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.