BoundaryML/baml · critical · BamlSysError

Symbol ' ' not found in BAML library

Error message

Symbol '{symbol}' not found in BAML library: {source}

What it means

`BamlSysError::SymbolNotFound` from baml-sys: the library loaded, but a required exported symbol (`symbol`) was missing, with the `libloading::Error` as source. This indicates the loaded library's exported API does not match what the Rust binding expects.

Solutions

  1. Rebuild the native BAML library from the matching source revision so it exports the expected symbol
  2. Align versions of the Rust binding package and the native library (reinstall both together)
  3. Verify the symbol exists with `nm -D` / `objdump -T` and correct the path to the intended library

Example fix

// before
let f: Symbol<...> = unsafe { lib.get(b"baml_invoke_v1")? }; // SymbolNotFound with stale lib
// after
let f: Symbol<...> = unsafe { lib.get(b"baml_invoke_v2")? }; // matches rebuilt library
Defensive patterns

Strategy: validation

Validate before calling

// verify required symbol before binding
if std::process::Command::new("nm").arg("-D").arg(lib_path)
    .output().map(|o| String::from_utf8_lossy(&o.stdout).contains("baml_invoke")).unwrap_or(false) { /* ok */ }

Try / catch

match load_baml_sys() {
    Err(BamlSysError::SymbolNotFound { symbol, source }) => {
        eprintln!("Native lib missing symbol {symbol}: {source}; rebuild native lib to match bindings");
    }
    Ok(sys) => { /* use sys */ }
}

Prevention

When it happens

Trigger: `lib.get(b"symbol_name")` failing because the loaded library is an older/newer build that doesn't export the expected FFI symbol.

Common situations: Rust bindings updated but native library stale (or vice versa); symbol renamed in a refactor; loading the wrong library file that lacks the export.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/578c506eaccc8b06. Report an issue: GitHub.

Appendix: source

Thrown at languages/rust/baml-sys/src/error.rs:22

/// Errors that can occur during library loading.
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)] // Error variants are self-documenting via #[error(...)]
pub enum BamlSysError {
    /// Library file not found at any search path.
    #[error("BAML library not found. Searched paths: {searched_paths:?}")]
    LibraryNotFound { searched_paths: Vec<PathBuf> },

    /// Failed to load the dynamic library.
    #[error("Failed to load BAML library from {path}: {source}")]
    LoadFailed {
        path: PathBuf,
        #[source]
        source: libloading::Error,
    },

    /// Symbol not found in loaded library.
    #[error("Symbol '{symbol}' not found in BAML library: {source}")]
    SymbolNotFound {
        symbol: &'static str,
        #[source]
        source: libloading::Error,
    },

    /// Version mismatch between Rust package and loaded library.
    #[error("Version mismatch: Rust package expects {expected}, but library reports {actual}")]
    VersionMismatch { expected: String, actual: String },

    /// Platform not supported.
    #[error("Platform not supported: {os}/{arch}")]
    UnsupportedPlatform {
        os: &'static str,
        arch: &'static str,
    },

    /// Failed to determine cache directory.

View on GitHub (pinned to bd85ce9dee)