Libdl
—ModuleThe Libdl module in Julia provides specialized and lower-level facilities for dynamic linking with shared libraries. While Julia inherently supports linking to runtime shared libraries through theccall
intrinsic,Libdl
extends this capability by offering additional, more granular control. It enables users to search for shared libraries both in memory and the filesystem, manually load them with specific runtime linker options, and look up library symbols as low-level pointers.
Base.Libc.Libdl.dlopen
—Functiondlopen(libfile::AbstractString [, flags::Integer]; throw_error:Bool = true)
Load a shared library, returning an opaque handle.
The extension given by the constantdlext
(.so
,.dll
, or.dylib
) can be omitted from thelibfile
string, as it is automatically appended if needed. Iflibfile
is not an absolute path name, then the paths in the arrayDL_LOAD_PATH
are searched forlibfile
, followed by the system load path.
The optional flags argument is a bitwise-or of zero or more ofRTLD_LOCAL
,RTLD_GLOBAL
,RTLD_LAZY
,RTLD_NOW
,RTLD_NODELETE
,RTLD_NOLOAD
,RTLD_DEEPBIND
, andRTLD_FIRST
. These are converted to the corresponding flags of the POSIX (and/or GNU libc and/or MacOS) dlopen command, if possible, or are ignored if the specified functionality is not available on the current platform. The default flags are platform specific. On MacOS the defaultdlopen
flags areRTLD_LAZY|RTLD_DEEPBIND|RTLD_GLOBAL
while on other platforms the defaults areRTLD_LAZY|RTLD_DEEPBIND|RTLD_LOCAL
. An important usage of these flags is to specify non default behavior for when the dynamic library loader binds library references to exported symbols and if the bound references are put into process local or global scope. For instanceRTLD_LAZY|RTLD_DEEPBIND|RTLD_GLOBAL
allows the library's symbols to be available for usage in other shared libraries, addressing situations where there are dependencies between shared libraries.
If the library cannot be found, this method throws an error, unless the keyword argumentthrow_error
is set tofalse
, in which case this method returnsnothing
.
From Julia 1.6 on, this method replaces paths starting with@executable_path/
with the path to the Julia executable, allowing for relocatable relative-path loads. In Julia 1.5 and earlier, this only worked on macOS.
Base.Libc.Libdl.dlopen_e
—Functiondlopen_e(libfile::AbstractString [, flags::Integer])
Similar todlopen
, except returnsC_NULL
instead of raising errors. This method is now deprecated in favor ofdlopen(libfile::AbstractString [, flags::Integer]; throw_error=false)
.
Base.Libc.Libdl.RTLD_NOW
—ConstantRTLD_DEEPBINDRTLD_FIRSTRTLD_GLOBALRTLD_LAZYRTLD_LOCALRTLD_NODELETERTLD_NOLOADRTLD_NOW
Enum constant fordlopen
. See your platform man page for details, if applicable.
Base.Libc.Libdl.dlsym
—Functiondlsym(handle, sym; throw_error::Bool = true)
Look up a symbol from a shared library handle, return callable function pointer on success.
If the symbol cannot be found, this method throws an error, unless the keyword argumentthrow_error
is set tofalse
, in which case this method returnsnothing
.
Base.Libc.Libdl.dlsym_e
—Functiondlsym_e(handle, sym)
Look up a symbol from a shared library handle, silently returnC_NULL
on lookup failure. This method is now deprecated in favor ofdlsym(handle, sym; throw_error=false)
.
Base.Libc.Libdl.dlclose
—Functiondlclose(handle)
Close shared library referenced by handle.
dlclose(::Nothing)
For the very common pattern usage pattern of
try hdl = dlopen(library_name) ... do somethingfinally dlclose(hdl)end
We define adlclose()
method that accepts a parameter of typeNothing
, so that user code does not have to change its behavior for the case thatlibrary_name
was not found.
Base.Libc.Libdl.dlext
—Constantdlext
File extension for dynamic libraries (e.g. dll, dylib, so) on the current platform.
Base.Libc.Libdl.dllist
—Functiondllist()
Return the paths of dynamic libraries currently loaded in aVector{String}
.
Base.Libc.Libdl.dlpath
—Functiondlpath(handle::Ptr{Cvoid})
Given a libraryhandle
fromdlopen
, return the full path.
dlpath(libname::Union{AbstractString, Symbol})
Get the full path of the librarylibname
.
Examples
julia> dlpath("libjulia")
Base.Libc.Libdl.find_library
—Functionfind_library(names [, locations])
Searches for the first library innames
in the paths in thelocations
list,DL_LOAD_PATH
, or system library paths (in that order) which can successfully be dlopen'd. On success, the return value will be one of the names (potentially prefixed by one of the paths in locations). This string can be assigned to aglobal const
and used as the library name in futureccall
's. On failure, it returns the empty string.
Base.DL_LOAD_PATH
—ConstantDL_LOAD_PATH
When callingdlopen
, the paths in this list will be searched first, in order, before searching the system locations for a valid library handle.
Settings
This document was generated withDocumenter.jl version 1.8.0 onWednesday 9 July 2025. Using Julia version 1.11.6.