SQLite Forum

Windows Build default compile options?
Login

Windows Build default compile options?

(1) By Will Iverson (wiverson) on 2021-12-07 03:43:15 [link] [source]

I'd like to have a Windows binary that basically is this but but with extensions (in particular session and r-tree).

sqlite-dll-win64-x64-3370000.zip 64-bit DLL (x64) for SQLite version 3.37.0.

I'm generating the build with the latest Visual Studio 2022 on a Windows install running via Parallels on my M1 MacBook. I'm using the x64 Native Tools Command Prompt for VS 2022.

Gotten as far as this which is generating a dll:

cl -O2 -DSQLITE_ENABLE_SESSION -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_RTREE -DSQLITE_DQS=0 -DSQLITE_ENABLE_COLUMN_METADATA sqlite3.c -link -dll -out:sqlite3.dll

But when I replace the prebuilt distro dll with the one I built, I'm getting this error in Unity.

EntryPointNotFoundException: sqlite3_libversion_number assembly:<unknown assembly> type:<unknown type> member:(null)
SQLite.SQLiteConnection..ctor (SQLite.SQLiteConnectionString connectionString) (at Assets/SQLite/SQLite.cs:292)

I've looked all over for the command line configuration used to generate the sqlite-dll-win64-x64-3370000.zip with no dice.

I looked at the compiler flags and there are a lot.

It looks like the compiler is stripping/not exporting the names...?

Any suggestions/pointers? Either to find the options for the build that match the other generated Windows binary, or is there something else I'm missing...?

Cheers, -Will

(2) By Larry Brasfield (larrybr) on 2021-12-07 04:06:49 in reply to 1 [source]

From a portion of the loader's complaint, "SQLite.SQLiteConnection..ctor", I gather that you are trying to use your sqlite3.dll with (I'm guessing) the System.Data.SQLite library. That library expects to link against something else to get to the SQLite APIs, namely something named SQLite.Interop.dll .

To build SQLite.Interop.dll, you will want its source, into which you might be able to incorporate the sqlite3.c you have for the one it is distributed with.

I doubt your problem is due solely to name stripping, exporting or decoration.

(3) By Keith Medcalf (kmedcalf) on 2021-12-07 04:07:26 in reply to 1 [link] [source]

Add the option (define) -DSQLITE_API=__desclspec(dllexport) to the command line.

cl -O2 -DSQLITE_API=__declspec(dllexport) -DSQLITE_ENABLE_SESSION -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_RTREE -DSQLITE_DQS=0 -DSQLITE_ENABLE_COLUMN_METADATA sqlite3.c -link -dll -out:sqlite3.dll

Some platforms export all global symbols by default, and some do not. Windows happens to be one of those platforms that does not export globals by default.

You must label them to be exported; or, you may use a method like the default Makefile.msc uses and generate a .def file and pass that in to the linker so that it knows what to do (differently than the default).

It is easier, SQLite3 is written such, that you can specify modifiers to prefix the various types of symbols (API, PRIVATE, etc). You define the API modifier, SQLITE_API to the value __declspec(dllexport) which will cause the compiler to add the dllexport to those declarations. The linker will then utilize that tag to export the named symbols from the DLL.

(4) By Will Iverson (wiverson) on 2021-12-07 04:16:39 in reply to 3 [link] [source]

That did the trick - awesome.

Seems like that would be important info to add to the How To Compile / Windows section.

Next steps, add a few bindings to the .NET wrapper I'm using (sqlite-net/SQLite.cs) and see if I can get that to wrap up the session support. Also generate a macOS version of sqlite3 that matches.

Again, thanks - no way I would have found that option.

(5) By Will Iverson (wiverson) on 2021-12-07 04:26:38 in reply to 3 [link] [source]

So the binary I generated is 1337856 bytes (apx 1.25mb), whereas the one I downloaded is 2150400 bytes (apx 2.15mb). Any guesses as the the reason for the delta? It's almost 2x...

(6) By Keith Medcalf (kmedcalf) on 2021-12-07 04:46:35 in reply to 5 [link] [source]

I believe that the default download is cross-compiled but the symbol table has not been stripped.

Again, inclusion of symbols in the symbol table is dependent on the platform. Some platform export the entire (global and private) symbol tables by default (and you use the strip command to remove them, or tell the compiler on the command line to strip the symbols). Other platforms (such as Microsoft) do not export a symbol table at all unless you specifically direct the compiler/linker to do that.

(7) By Will Iverson (wiverson) on 2021-12-07 17:44:44 in reply to 6 [link] [source]

Cross-compiled for 32 and 64? AFAIK no Windows ARM?

The posted build is labeled as 64-bit DLL (x64) for SQLite version 3.37.0. There's another 32-bit build.

Hmm.

(8) By anonymous on 2023-01-12 05:03:18 in reply to 7 [link] [source]

How to generate specific version of sqlite3.dll through command