SQLite Forum

Help with compiling extension

Help with compiling extension

(1) By anonymous on 2021-06-21 00:58:32 [link] [source]

I'm trying to compile statement_vtab from https://github.com/0x09/sqlite-statement-vtab.

I've successfully compiled and run this in sqlite on Linux, but having difficulty on Win10.

The following seems to successfully compile:

i686-w64-mingw32-gcc -shared -o statement_vtab.dll statement_vtab.c

But when I try to use this (in SQLite version 3.36.0) ...

.load ./statement_vtab.dll

CREATE VIRTUAL TABLE temp_1 USING statement (( SELECT 1 ));

The test case crashes sqlite and a message box id is displayed with a generic error message: "A problem caused the program to stop working ...".

Any advice would be appreciated.

(2) By Larry Brasfield (larrybr) on 2021-06-21 03:35:18 in reply to 1 [source]

I am unable to replicate your problem when I use a 64-bit, v3.36.0 CLI shell and the exact code and gcc invocation you provide. It works just as I would expect, with a functioning temp_1 virtual table.

Are you perchance using the distributed, 32-bit CLI shell and a 64-bit DLL, with failure occurring at the .load step? If so, mixed "bitness" is your problem.

(3) By anonymous on 2021-06-21 07:18:34 in reply to 2 [link] [source]

Thanks for the advice -- I got it to work.

For future reference what I did was to ...

1. Open MSYS2 MinGW 64-bit terminal.
2. Download two additional packages:
    pacman -S mingw-w64-x86_64-toolchain
    pacman -S mingw-w64-x86_64-dlfcn
3.  Compile a 64 bit version of sqlite CLI:
    x86_64-w64-mingw32-gcc -ldl -lm -o sqlite3 shell.c sqlite3.c
4.  Compile the extension:
    x86_64-w64-mingw32-gcc -shared statement_vtab.c -o statement_vtab.dll