function

ffi.dlopen

function dlopen<Fns extends Record<string, FFIFunction>>(
name: string | BunFile | URL,
symbols: Fns
): Library<Fns>;

Open a native library and load symbols from it

@param name

Library name or file path, passed to dlopen()

@param symbols

Map of symbols to load where the key is the symbol name and the value is the FFIFunction

import {dlopen} from 'bun:ffi';

const lib = dlopen("duckdb.dylib", {
  get_version: {
    returns: "cstring",
    args: [],
  },
});
lib.symbols.get_version();
// "1.0.0"

Referenced types

class URL

The URL interface represents an object providing static methods used for creating object URLs.

MDN Reference

interface Library<Fns extends Symbols>

  • close(): void;

    dlclose the library, unloading the symbols and freeing allocated memory.

    Once called, the library is no longer usable.

    Calling a symbol from a closed cc library throws a TypeError. Calling a symbol from a closed dlopen or linkSymbols library is undefined behavior.