rust call sqlite3 error: linking with `link.exe` failed: exit code: 1181

发布时间 2023-12-26 22:58:12作者: 咕咚!

rust call sqlite3 error: linking with link.exe failed: exit code: 1181

声明:本文禁止csdn.net及所有所有子网站转载。禁止以营利性为目的的转载。

报错

error: linking with `link.exe` failed: exit code: 1181                                                                              
  |
  = note: ...
  ....
  = note: LINK : fatal error LNK1181: 无法打开输入文件“sqlite3.lib”


warning: `demo` (bin "demo") generated 1 warning                                                                                    
error: could not compile `demo` (bin "demo") due to previous error; 1 warning emitted

Cargo.toml

[package]
name = "demo"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rusqlite = { version = "0.30.0", features = ["winsqlite3"] }

src/main.rs

use rusqlite::{Connection, Result};

#[derive(Debug)]
struct Person {
    id: i32,
    name: String,
    data: Option<Vec<u8>>,
}

fn main() -> Result<()> {
    let conn = Connection::open("person.db")?;

    conn.execute(
        "CREATE TABLE person (
            id    INTEGER PRIMARY KEY,
            name  TEXT NOT NULL,
            data  BLOB
        )",
        (), // empty list of parameters.
    )?;
    let me = Person {
        id: 0,
        name: "Roc".to_string(),
        data: None,
    };
    conn.execute(
        "INSERT INTO person (name, data) VALUES (?1, ?2)",
        (&me.name, &me.data),
    )?;

    let mut stmt = conn.prepare("SELECT id, name, data FROM person")?;
    let person_iter = stmt.query_map([], |row| {
        Ok(Person {
            id: row.get(0)?,
            name: row.get(1)?,
            data: row.get(2)?,
        })
    })?;

    for person in person_iter {
        println!("Found person {:?}", person.unwrap());
    }
    Ok(())
}

通过添加winsqlite3特性来解决:

cargo add rusqlite --features winsqlite3