Compiling DLLs on your own can get really messy and take a lot of time (e.g. FFmpeg) if you are not really into this stuff. SQLite is one of the positive examples which make it really easy: download the amalgamation source, and follow the DLL compilation guide. The nicest thing for Windows users is that you can just use the Visual Studio compiler to compile x86 and x64 versions without any configuration or dependencies and just a single short command, and don’t need to fool around with Cygwin/MinGW/MSYS/MinGW-W64/Win-builds etc.
Unfortunately there’s a small detail missing in the SQLite guide, and they don’t seem to have an easy way of contacting them except for an antiquated mailing list. So I’m posting here where nobody is ever going to find it:
cl sqlite3.c -link -dll -out:sqlite3.dll
The line above is the recommended command for the MSVC command prompt to compile an SQLite DLL. The problem is, it does not export any functions, does not create a .lib for native programming, and cannot be p/invoked from .NET/C# (raising an EntryPointNotFoundException).
The solution is to export the API functions by setting the SQLITE_API preprocessor definition:
cl sqlite3.c -DSQLITE_API=__declspec(dllexport) -link -dll -out:sqlite3.dll
To test if your DLL is exporting functions, you can either run dumpbin /exports sqlite3.dll
on the command line or use the Dependency Walker and check the export function list (where the first column is called “E”).
timwah
“where nobody is ever going to find it”. I found it, and THANK YOU
dougwj
Thank you, this has been driving me crazy!
x64
so so sooooooo thx
Michael
Found it. Thanks,
KaFu
Found it too :), much appreciated!
TheRaven
Found it myself, and it still fills a void even after all this time.
Windows 10 has achieved a level of complexity that makes everything more prone to confusion and frustration making this post incredibly valuable; many thnx to you for sharing your experience.
Vsevolod
Thanks a lot!
For me (win8.1, sqlite 3.16.2, VS2015 Express) works only:
cl sqlite3.c -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_JSON1 -DSQLITE_API=__declspec(dllexport) -link -dll -out:sqlite3.dll
Pesho
THANKS!