0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

rusqliteの自動生成コードが動かない

Posted at

環境(使用ツールなど)

  • WSL
    • Ubuntu
  • Rust
  • VSCode

事象

いつも通りRustのプロジェクトを作成します。今回はrusqliteを使いたいので追加。

$ cargo new sqlite-test
$ cd sqlite-test
$ cargo add rusqlite

するとVSCode上でコードのエラーが発生。

cargo runしてもこの有様。

   Compiling libsqlite3-sys v0.35.0
error: prefix `c` is unknown
  --> /home/kaminari/rust-projects/sqlite-test/target/debug/build/libsqlite3-sys-7734deb9b5d1b7bd/out/bindgen.rs:26:47
   |
26 | pub const SQLITE_VERSION: &::std::ffi::CStr = c"3.14.0";
   |                                               ^ unknown prefix
   |
   = note: prefixed identifiers and literals are reserved since Rust 2021
help: consider inserting whitespace here
   |
26 | pub const SQLITE_VERSION: &::std::ffi::CStr = c "3.14.0";
   |                                                +

error: prefix `c` is unknown
  --> /home/kaminari/rust-projects/sqlite-test/target/debug/build/libsqlite3-sys-7734deb9b5d1b7bd/out/bindgen.rs:29:5
   |
29 |     c"2016-08-08 13:40:27 d5e98057028abcf7217d0d2b2e29bbbcdf09d6de";
   |     ^ unknown prefix
   |
   = note: prefixed identifiers and literals are reserved since Rust 2021
help: consider inserting whitespace here
   |
29 |     c "2016-08-08 13:40:27 d5e98057028abcf7217d0d2b2e29bbbcdf09d6de";
   |      +

error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, or an operator, found `"3.14.0"`
  --> /home/kaminari/rust-projects/sqlite-test/target/debug/build/libsqlite3-sys-7734deb9b5d1b7bd/out/bindgen.rs:26:48
   |
26 | pub const SQLITE_VERSION: &::std::ffi::CStr = c"3.14.0";
   |                                                ^^^^^^^^ expected one of 7 possible tokens

error[E0531]: cannot find unit struct, unit variant or constant `SQLITE_INTERNAL` in module `super`
  --> /home/kaminari/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libsqlite3-sys-0.35.0/src/error.rs:69:20
   |
69 |             super::SQLITE_INTERNAL => ErrorCode::InternalMalfunction,
   |                    ^^^^^^^^^^^^^^^ not found in `super`

error[E0531]: cannot find unit struct, unit variant or constant `SQLITE_PERM` in module `super`
  --> /home/kaminari/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libsqlite3-sys-0.35.0/src/error.rs:70:20
   |
70 |             super::SQLITE_PERM => ErrorCode::PermissionDenied,
   |                    ^^^^^^^^^^^ not found in `super`

error[E0531]: cannot find unit struct, unit variant or constant `SQLITE_ABORT` in module `super`
  --> /home/kaminari/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libsqlite3-sys-0.35.0/src/error.rs:71:20
   |
71 |             super::SQLITE_ABORT => ErrorCode::OperationAborted,
   |                    ^^^^^^^^^^^^ not found in `super`

error[E0531]: cannot find unit struct, unit variant or constant `SQLITE_BUSY` in module `super`
  --> /home/kaminari/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libsqlite3-sys-0.35.0/src/error.rs:72:20
   |
72 |             super::SQLITE_BUSY => ErrorCode::DatabaseBusy,
   |                    ^^^^^^^^^^^ not found in `super`

error[E0531]: cannot find unit struct, unit variant or constant `SQLITE_LOCKED` in module `super`
  --> /home/kaminari/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libsqlite3-sys-0.35.0/src/error.rs:73:20
   |
73 |             super::SQLITE_LOCKED => ErrorCode::DatabaseLocked,
   |                    ^^^^^^^^^^^^^ not found in `super`

error[E0531]: cannot find unit struct, unit variant or constant `SQLITE_NOMEM` in module `super`
  --> /home/kaminari/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libsqlite3-sys-0.35.0/src/error.rs:74:20
   |
74 |             super::SQLITE_NOMEM => ErrorCode::OutOfMemory,
   |                    ^^^^^^^^^^^^ not found in `super`

error[E0531]: cannot find unit struct, unit variant or constant `SQLITE_READONLY` in module `super`
  --> /home/kaminari/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libsqlite3-sys-0.35.0/src/error.rs:75:20
   |
75 |             super::SQLITE_READONLY => ErrorCode::ReadOnly,
   |                    ^^^^^^^^^^^^^^^ not found in `super`

(中略)

error[E0412]: cannot find type `sqlite3_vtab_cursor` in this scope
  --> /home/kaminari/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libsqlite3-sys-0.35.0/src/lib.rs:35:18
   |
35 | impl Default for sqlite3_vtab_cursor {
   |                  ^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0658]: the `#[expect]` attribute is an experimental feature
 --> /home/kaminari/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libsqlite3-sys-0.35.0/src/lib.rs:1:1
  |
1 | #![expect(non_snake_case, non_camel_case_types)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #54503 <https://github.com/rust-lang/rust/issues/54503> for more information

Some errors have detailed explanations: E0412, E0425, E0531, E0658.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `libsqlite3-sys` (lib) due to 139 previous errors

rusqliteに必要なlibsqlite3-sysがコンパイルできていない様子です。

解決

Rustのバージョンアップをしてなかっただけでした。

$ rustc --version
rustc 1.72.0 (5680fa18f 2023-08-23)
$ rustup update
(中略)
$ rustc --version
rustc 1.89.0 (29483883e 2025-08-04)

結論

バージョンアップをサボるのはやめよう!

余談

とはいえ、競プロをしている身としてはこまめなバージョンアップは不要(というより、ジャッジ環境で使えない関数などを踏む可能性があり、むしろ下手なバージョンアップは害になりうる)。
競プロ用とアプリ開発用で環境を分けているので今回は問題ないが、競プロを引退しない限り一生つきまとう問題なので悩ましい。
(これ系の問題だとジャッジ環境のバージョンでrust-analyzerがサポート対象外になるのがもっと深刻)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?