I'm trying to compile SQLite with a C program along with at least one loadable non-core SQLite extension, as statically linked, expecting that to mean that there will be one executable file generated that will depend on no other files at that point.
Right now, I'm trying to just get carray.c loaded. I have the carray.c file and the carray.h file. I've read the SQLite instructions for run-time loadable extensions, especially item 6 for statically linking; but I really don't know enough to understand it properly.
In item 6 of the instructions, would you please tell me the following?
- Where it reads,
To statically link your extension, simply add the -DSQLITE_CORE compile-time optiondoes this apply to compiling thesqlite3.cfile, thecarray.cfile, or both? And how is this to be done?
I should've said I'm using minGW-W64. I have been compiling the sqlite3.c amalgamation file with my C file by first generating a sqlite3.o file using, gcc -O2 -c sqlite3.c -DSQLITE_ENABLE_JSON1 and then compiling that with my ever-changing code as gcc -O2 sqlite3.o myfile.c -o myfile.exe. And this has been working until trying to incorporate the carray loadable extension.
Earlier I tried compiling sqlite3.c and carray.c each to their own .o files and then compiling them with myfile.c and it compiled without error; but carray was not recognized as a function when I tried to use it. I think it is the initializing/entry point item that is the problem.
- I think I understand the name changing regarding
SQLITE_EXTENSION_INITand think I need to ussqlite3_auto_extension()because my C program will require multiple connections, not to the same database file but to multiple files. However, I get very confused at this point. When reading the documentation onsqlite3_auto_extension(), I've no idea what an entry point is or how to use/providexEntryPoint. It also appears that the database handle is to be passed intoxEntryPointand that confuses me because I thought this was to automatically load the extension into every database connection not just for one handle.
It also reads that Then modify your application to invoke the entry point directly, passing in a NULL pointer as the third "pApi" parameter. I think it reads elsewhere that this is to be done near the beginning of the main C function, but I don't follow how to do it.
- Is the
carray.hfile to be included in my C program?
This SQLite Forum question, especially at post (3), regarding including the extension source in the amalgamation file, is interesting and I think I almost follow it; but don't understand how it compares to the regular instructions, or if it is a better method.
- If possible, could you please explain what placing SQLITE_EXTENSION_INIT1 on a line by itself does or how compiling with -DSQLITE_CORE makes it a no-op?
Thank you.
The SQLite forum post mentioned above works. I just appended carray.c to the sqlite3.c amalgamation file, then appended the core_init() function example after it, changed one sqlite3_auto_extension((void*)sqlite3_autobusy_init); to use sqlite3_carray_init, and commented out the other since currently have just one extension to link, and included carray.h in my code. Then compiled the amalgamation as gcc -O2 -c sqlite3.c -DSQLITE_ENABLE_JSON1 -DSQLITE_EXTRA_INIT=core_init. You don't need the first one with JSON1 but I left it in to make sure they'd work together. I'd still like to know how to do the same using the method in the instructions.
Clarification on how to add the extension following the instructions, rather than appending to the amalgamation file, can be found here at this SQLite Forum post.