Compiling an SQLite3 Extension

· 156 words · 1 minute read

Uh, I don’t know C… at all. How on earth do I compile an extension for SQLite3?!

Here’s how I compiled and used the UUID extension on Ubuntu.

  1. Install libsqlite3-dev
  2. Clone the SQLite repository. Techinically it’s a Fossil project, but imma just clone from Github.
  3. Compile.
  4. Optional. Move to a more global location.
sudo apt install libsqlite3-dev
git clone https://github.com/sqlite/sqlite
gcc -fPIC -shared sqlite/ext/misc/uuid.c -o uuid.so -lm
sudo mv uuid.so /usr/lib/uuid.so

There’s probably a better place than /usr/lib/ to put that… But what do I know?

It’s not necessary to put it somewhere globally accessible, either:

# uuid.so is located in ./
$ sqlite3
sqlite3> .load ./uuid
# uuid.so is located in /usr/lib
$ sqlite3
sqlite> .load uuid

You see? It’s just a convenience if it’s globally accessible.

Just to prove the point that the extension works:

sqlite> create table foo (id text);
sqlite> insert into foo (id) values (uuid());
sqlite> select * from foo;
8af44718-f0ee-42d4-b3ba-2f4d99320e2f