Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

raw-dylib works for elf too

raw-dylib works to link against external symbols without having the actual library around at link time. The compiler/linker will generate the necessary parts and emit a NEEDED Elf entry for the named library as well as undefined symbols to be resolved at elf load time by the system linker.

#![allow(incomplete_features)]
#![feature(raw_dylib_elf)]
#![feature(extern_types)]

use std::ptr;
use std::ffi::{c_int, c_char};

unsafe extern "C" {
    type sqlite3;
}

#[link(name = "libsqlite3.so", kind = "raw-dylib", modifiers = "+verbatim")]
unsafe extern "C" {
    fn sqlite3_open(filename: *const c_char, db: *mut *mut sqlite3) -> c_int;
}

fn main() {
    unsafe {
        let mut handle: *mut sqlite3 = ptr::null_mut();
        let res = sqlite3_open(c":memory:".as_ptr(), &mut handle);
        println!("res={res}");
    }
}
Last change: , commit: bdc04ab