tonhowtf/omniget · error

PDFium sem

Error message

PDFium sem {}: {}

What it means

pdf.rs's unsafe sym<T> helper wraps libloading Library::get failures: a required PDFium C symbol could not be resolved from the loaded library. This means the loaded shared library is not the expected PDFium (or is an incompatible build missing that export). The message names the missing symbol (e.g. FPDF_InitLibrary) plus the libloading error.

Solutions

  1. Replace the PDFium library with a complete official build (pdfium-binaries / bundled dependency) matching the platform
  2. Check that the resolved path really points to PDFium (not a similarly named library)
  3. Use a PDFium build recent enough to export all required FPDF_* symbols (e.g. FPDF_LoadMemDocument64)
  4. If the symbol is genuinely optional, use the crate's opt_sym path instead of the required one

Example fix

// before
let lib = unsafe { libloading::Library::new(path) }?;
let f = unsafe { sym::<LoadMemDoc>(&lib, b"FPDF_LoadMemDocument64\0")? }; // 'PDFium sem ...'
// after
let f = match unsafe { opt_sym::<LoadMemDoc>(&lib, b"FPDF_LoadMemDocument64\0") } {
    Some(f) => f,
    None => return Err(anyhow!("PDFium desatualizado: reinstale em Ajustes → Dependências")),
};
Defensive patterns

Strategy: try-catch

Validate before calling

// probe the library before use
let lib = unsafe { libloading::Library::new(pdfium_path) }
    .map_err(|e| anyhow!("PDFium inválido em {}: {e}", pdfium_path.display()))?;
unsafe { lib.get::<usize>(b"FPDF_InitLibrary\0") }
    .map_err(|_| anyhow!("PDFium incompleto: reinstale em Ajustes → Dependências"))?;

Try / catch

match pdf::info(&path) {
    Err(e) if e.to_string().contains("PDFium sem ") => {
        eprintln!("{e}\nBiblioteca PDFium incompatível — reinstale via Ajustes → Dependências.");
    }
    other => other?,
}

Prevention

When it happens

Trigger: Loading a PDFium shared library whose build lacks a required export — a stub/wrong library placed at the resolved path, a severely outdated or incompatible PDFium build, or symbol name mismatch on an unusual platform build.

Common situations: User configured 'pdfium.dll' that is actually a different PDF library; distro PDFium builds with different symbol visibility; mixed-version PDFium where newer API symbols (LoadMemDocument64, etc.) do not exist in an old library.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/e4c18fb4793b12ca. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/core/tools/pdf.rs:110

    obj_bounds:
        Option<unsafe extern "C" fn(Object, *mut f32, *mut f32, *mut f32, *mut f32) -> c_int>,
    img_bitmap: Option<unsafe extern "C" fn(Object) -> Bitmap>,
    bmp_format: Option<unsafe extern "C" fn(Bitmap) -> c_int>,
    bmp_w: Option<unsafe extern "C" fn(Bitmap) -> c_int>,
    bmp_h: Option<unsafe extern "C" fn(Bitmap) -> c_int>,
}

unsafe impl Send for Api {}
unsafe impl Sync for Api {}

static API: Mutex<Option<&'static Api>> = Mutex::new(None);
/// O PDFium não é thread-safe: toda operação segura este lock.
static OPS: Mutex<()> = Mutex::new(());

unsafe fn sym<T: Copy>(lib: &libloading::Library, name: &[u8]) -> anyhow::Result<T> {
    Ok(*lib
        .get::<T>(name)
        .map_err(|e| anyhow!("PDFium sem {}: {}", String::from_utf8_lossy(name), e))?)
}

/// Igual ao `sym`, mas o símbolo pode faltar: devolve `None` em vez de erro.
unsafe fn opt_sym<T: Copy>(lib: &libloading::Library, name: &[u8]) -> Option<T> {
    lib.get::<T>(name).ok().map(|s| *s)
}

fn api() -> anyhow::Result<&'static Api> {
    let mut guard = API.lock().unwrap_or_else(|p| p.into_inner());
    if let Some(a) = *guard {
        return Ok(a);
    }
    let path = crate::core::pdfium::resolve_path()
        .ok_or_else(|| anyhow!("PDFium nao esta instalado (Ajustes → Dependencias → PDFium)"))?;
    let lib = unsafe { libloading::Library::new(&path) }
        .map_err(|e| anyhow!("nao carregou o PDFium em {}: {}", path.display(), e))?;
    let api = unsafe {
        let init: unsafe extern "C" fn() = sym(&lib, b"FPDF_InitLibrary\0")?;

View on GitHub (pinned to 8600b91f42)