Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to load SQLite3 Dynamic Library – example code not working #105

Closed
jerrygreen opened this issue Aug 4, 2023 · 6 comments
Closed

Comments

@jerrygreen
Copy link

I'm trying to run this code sample from readme:

import { Database } from "https://deno.land/x/[email protected]/mod.ts"

const db = new Database("test.db")

const [version] = db.prepare("select sqlite_version()").value<[string]>()!
console.log(version)

db.close()

And I'm getting this error:

error: Uncaught (in promise) Error: Failed to load SQLite3 Dynamic Library
  throw new Error("Failed to load SQLite3 Dynamic Library", { cause: e });
        ^
    at https://deno.land/x/[email protected]/src/ffi.ts:618:9
    at eventLoopTick (ext:core/01_core.js:183:11)
Caused by: TypeError: Deno.dlopen is not a function
    at dlopen (https://deno.land/x/[email protected]/mod.ts:155:15)
    at eventLoopTick (ext:core/01_core.js:183:11)
    at async https://deno.land/x/[email protected]/src/ffi.ts:601:7

It might be somehow related to this:

I think of this relation because I'm also using aarch64 / Raspberry Pi. But it's another error so idk.

Version info:

deno --version
deno 1.36.0 (release, aarch64-unknown-linux-gnu)
v8 11.6.189.12
typescript 5.1.6
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:        20.04
Codename:       focal

I already used dozens of other deno packages, they work perfectly fine.

@DjDeveloperr
Copy link
Member

DjDeveloperr commented Aug 4, 2023

I don't think this library works on aarch64 linux yet. But let us try anyway! The error you have posted simply means that you did not pass the --unstable flag.

I do not have an actual aarch64 Linux machine to test on. But I will investigate this issue further over the weekend. I can probably natively virtualize Linux on Arm-based Mac.

@jerrygreen
Copy link
Author

jerrygreen commented Aug 4, 2023

Oh, my bad. Tried --unstable flag and I now get two errors, same and new one:

deno run -A --unstable test.ts
error: Uncaught (in promise) Error: Failed to load SQLite3 Dynamic Library
  throw new Error("Failed to load SQLite3 Dynamic Library", { cause: e });
        ^
    at https://deno.land/x/[email protected]/src/ffi.ts:618:9
    at eventLoopTick (ext:core/01_core.js:183:11)
Caused by: Error: Could not open library: Could not open library: /lib/aarch64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /home/ubuntu/.cache/deno/plug/https/github.com/3cb5e608efce656445a255c1ab6f4d25155f9e25e344dc43ab8a196786e951cf.so)
    at new DynamicLibrary (ext:deno_ffi/00_ffi.js:440:46)
    at Object.dlopen (ext:deno_ffi/00_ffi.js:577:10)
    at dlopen (https://deno.land/x/[email protected]/mod.ts:155:15)
    at eventLoopTick (ext:core/01_core.js:183:11)
    at async https://deno.land/x/[email protected]/src/ffi.ts:601:7

Maybe if I update glibc, it will be solved, but... Is this an absolute necessity? I mean, I have Ubuntu 20.04.2 LTS installed, it's not that old... And granularly updating glibc would be pain in the ass and practically not very healthy for the OS in overall, I guess... Kinda fundamental dependency.

ldd --version
ldd (Ubuntu GLIBC 2.31-0ubuntu9.7) 2.31
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

I tried older versions of deno-sqlite3, but they don't work it seems: it's trying to download libsqlite3_aarch64.so but they're present only in the recent releases, 0.9.0 and 0.9.1, – both same error.

What do you think? Updating glibc, or an OS, – the only right way forward?

@DjDeveloperr
Copy link
Member

Do you have sqlite installed on your system? You can try using the default sqlite. To do that, set DENO_SQLITE_PATH to full path to the library file present on your system.

@jerrygreen
Copy link
Author

jerrygreen commented Aug 5, 2023

Yes, sqlite3 is installed:

sqlite3 --version
3.31.1 2020-01-27 19:55:54 3bfa9cc97da10598521b342961df8f5f68c7388fa117345eeb516eaa837balt1

If I set path explicitly, the error is a bit different but still there:

DENO_SQLITE_PATH=/usr/bin/sqlite3 deno run -A --unstable test.ts
error: Uncaught Error: Failed to load SQLite3 Dynamic Library
  throw new Error("Failed to load SQLite3 Dynamic Library", { cause: e });
        ^
    at https://deno.land/x/[email protected]/src/ffi.ts:618:9
Caused by: Error: Could not open library: Could not open library: /usr/bin/sqlite3: cannot dynamically load position-independent executable
    at new DynamicLibrary (ext:deno_ffi/00_ffi.js:440:46)
    at Object.dlopen (ext:deno_ffi/00_ffi.js:577:10)
    at https://deno.land/x/[email protected]/src/ffi.ts:598:16

I might be wrong, but this new error, /usr/bin/sqlite3: cannot dynamically load position-independent executable, seems to be related to same glibc, so it's probably the same issue, just told in two different ways by some reason. I also tried just sqlite (not sqlite3), – which leaves the same error.

Is it possible to set custom path for glibc? I think if glibc is, truly, the only reason, then this workaround would be enough for me. At least it would simplify debugging, as I don't have to replace my system-level glibc.

@DjDeveloperr
Copy link
Member

You need to point the path to sqlite3 shared library not the binary. It would look like libsqlite3.so.

@jerrygreen
Copy link
Author

Hooray, it works! Thanks.

I'd add some details to whatever people coming here after. I first found several .so files:

2>/dev/null find / -name libsqlite3.so
/snap/gnome-3-38-2004/145/usr/lib/aarch64-linux-gnu/libsqlite3.so
/snap/gnome-3-38-2004/141/usr/lib/aarch64-linux-gnu/libsqlite3.so
/snap/gnome-42-2204/122/usr/lib/aarch64-linux-gnu/libsqlite3.so
/snap/gnome-42-2204/112/usr/lib/aarch64-linux-gnu/libsqlite3.so
/snap/lxd/23999/lib/libsqlite3.so
/snap/lxd/24065/lib/libsqlite3.so

I tried them all, some of them returned errors just like in already mentioned issue:

DENO_SQLITE_PATH=/snap/lxd/24065/lib/libsqlite3.so deno run -A --unstable test.ts
Segmentation fault (core dumped)

Some returned the same Failed to load SQLite3 Dynamic Library error:

DENO_SQLITE_PATH=/snap/gnome-42-2204/112/usr/lib/aarch64-linux-gnu/libsqlite3.so deno run -A --unstable test.ts
error: Uncaught Error: Failed to load SQLite3 Dynamic Library
  throw new Error("Failed to load SQLite3 Dynamic Library", { cause: e });
        ^
    at https://deno.land/x/[email protected]/src/ffi.ts:618:9
Caused by: Error: Could not open library: Could not open library: /lib/aarch64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /snap/gnome-42-2204/112/usr/lib/aarch64-linux-gnu/libsqlite3.so)
    at new DynamicLibrary (ext:deno_ffi/00_ffi.js:440:46)
    at Object.dlopen (ext:deno_ffi/00_ffi.js:577:10)
    at https://deno.land/x/[email protected]/src/ffi.ts:598:16

✅ And with one, deno actually executed example code without errors, correctly logging sqlite version:

DENO_SQLITE_PATH=/snap/gnome-3-38-2004/145/usr/lib/aarch64-linux-gnu/libsqlite3.so deno run -A --unstable test.ts
3.41.2

Weirdly though, it shows different version than sqlite3 --version:

sqlite3 --version
3.31.1 2020-01-27 19:55:54 3bfa9cc97da10598521b342961df8f5f68c7388fa117345eeb516eaa837balt1

So I guess I have several sqlite3 installed and some of them don't work, including this one used by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants