You can use a custom-compiled version of SQLite with your Crystal application using two different methods: specifying the library at runtime or hardcoding the path at compile time.
Method 1: Specify library location at runtime (Recommended)
This method allows you to point to a different library location without rebuilding the binary. Use the LD_LIBRARY_PATH environment variable.
To run directly:
LD_LIBRARY_PATH=/path/to/sqlite_dir crystal run src/app.cr
To build a release binary that uses the custom library at runtime:
crystal build --release --link-flags -L"$(realpath /path/to/sqlite_dir/libsqlite3.so.0)" src/app.cr
LD_LIBRARY_PATH=/path/to/sqlite_dir ./app
You can verify which library is being linked using ldd:
LD_LIBRARY_PATH=/path/to/sqlite_dir ldd ./app
Method 2: Specify absolute path at compile time
This method embeds the specific path into the binary. Note that the resulting binary will only work if the library remains at that exact location.
To run directly:
crystal run --link-flags "$(realpath /path/to/sqlite_dir/libsqlite3.so.0)" src/app.cr
To build a release binary:
crystal build --release --link-flags "$(realpath /path/to/sqlite_dir/libsqlite3.so.0)" src/app.cr
./app
Verify the link with:
ldd ./app
crystal build --release --link-flags -L"$(realpath ../sqlite-amalgamation-3370000/libsqlite3.so.0)" src/app.cr
LD_LIBRARY_PATH=../sqlite-amalgamation-3370000 ./app