无法在 Windows 上构建 sqlcipher3

Unable to build sqlcipher3 on Windows

构建 sqlcipher 后,将 sqlite3.c 和 sqlite3.h 复制到根文件夹中,我正在尝试构建 sqlcipher3(在 Windows 10,Python 3.9.0):

C:\dev\py\sqlcipher3# setup.py build_static build
running build_static
Builds a C extension using a sqlcipher amalgamation
building 'sqlcipher3._sqlite3' extension
C:\Program Files (x86)\Microsoft Visual Studio19\BuildTools\VC\Tools\MSVC.28.29333\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DMODULE_NAME="sqlcipher3.dbapi2" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS3_PARENTHESIS=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_FTS5=1 -DSQLITE_ENABLE_JSON1=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_STAT4=1 -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_SOUNDEX=1 -DSQLITE_USE_URI=1 -DSQLITE_TEMP_STORE=2 -DSQLITE_MAX_VARIABLE_NUMBER=250000 -DSQLITE_DEFAULT_PAGE_SIZE=4096 -DSQLITE_DEFAULT_CACHE_SIZE=-8000 -Dinline=__inline -I. -IC:\OpenSSL-Win64\include -IC:\Python\include -IC:\Python\include -IC:\Program Files (x86)\Microsoft Visual Studio19\BuildTools\VC\Tools\MSVC.28.29333\include -IC:\Program Files (x86)\Windows Kits\NETFXSDK.8\include\um -IC:\Program Files (x86)\Windows Kits\include.0.18362.0\ucrt -IC:\Program Files (x86)\Windows Kits\include.0.18362.0\shared -IC:\Program Files (x86)\Windows Kits\include.0.18362.0\um -IC:\Program Files (x86)\Windows Kits\include.0.18362.0\winrt -IC:\Program Files (x86)\Windows Kits\include.0.18362.0\cppwinrt /Tc.\sqlite3.c /Fobuild\temp.win-amd64-3.9\Release.\sqlite3.obj
sqlite3.c
.\sqlite3.c(24335): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Program Files (x86)\Microsoft Visual Studio19\BuildTools\VC\Tools\MSVC.28.29333\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DMODULE_NAME="sqlcipher3.dbapi2" -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS3_PARENTHESIS=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_FTS5=1 -DSQLITE_ENABLE_JSON1=1 -DSQLITE_ENABLE_LOAD_EXTENSION=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_STAT4=1 -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1 -DSQLITE_HAS_CODEC=1 -DSQLITE_SOUNDEX=1 -DSQLITE_USE_URI=1 -DSQLITE_TEMP_STORE=2 -DSQLITE_MAX_VARIABLE_NUMBER=250000 -DSQLITE_DEFAULT_PAGE_SIZE=4096 -DSQLITE_DEFAULT_CACHE_SIZE=-8000 -Dinline=__inline -I. -IC:\OpenSSL-Win64\include -IC:\Python\include -IC:\Python\include -IC:\Program Files (x86)\Microsoft Visual Studio19\BuildTools\VC\Tools\MSVC.28.29333\include -IC:\Program Files (x86)\Windows Kits\NETFXSDK.8\include\um -IC:\Program Files (x86)\Windows Kits\include.0.18362.0\ucrt -IC:\Program Files (x86)\Windows Kits\include.0.18362.0\shared -IC:\Program Files (x86)\Windows Kits\include.0.18362.0\um -IC:\Program Files (x86)\Windows Kits\include.0.18362.0\winrt -IC:\Program Files (x86)\Windows Kits\include.0.18362.0\cppwinrt /Tcsrc\blob.c /Fobuild\temp.win-amd64-3.9\Release\src\blob.obj
blob.c
src\blob.c(178): warning C4244: 'function': conversion from 'Py_ssize_t' to 'int', possible loss of data
src\blob.c(359): warning C4244: 'function': conversion from 'Py_ssize_t' to 'int', possible loss of data
src\blob.c(386): warning C4244: 'function': conversion from 'Py_ssize_t' to 'int', possible loss of data
src\blob.c(408): warning C4244: 'function': conversion from 'Py_ssize_t' to 'int', possible loss of data
src\blob.c(421): warning C4244: 'function': conversion from 'Py_ssize_t' to 'int', possible loss of data
src\blob.c(421): warning C4244: 'function': conversion from 'Py_ssize_t' to 'int', possible loss of data
src\blob.c(439): warning C4244: 'function': conversion from 'Py_ssize_t' to 'int', possible loss of data
src\blob.c(439): warning C4244: 'function': conversion from 'Py_ssize_t' to 'int', possible loss of data
src\blob.c(508): warning C4244: 'function': conversion from 'Py_ssize_t' to 'int', possible loss of data
src\blob.c(536): warning C4244: 'function': conversion from 'Py_ssize_t' to 'int', possible loss of data
src\blob.c(550): warning C4244: 'function': conversion from 'Py_ssize_t' to 'int', possible loss of data
src\blob.c(550): warning C4244: 'function': conversion from 'Py_ssize_t' to 'int', possible loss of data
src\blob.c(574): warning C4244: 'function': conversion from 'Py_ssize_t' to 'int', possible loss of data
src\blob.c(574): warning C4244: 'function': conversion from 'Py_ssize_t' to 'int', possible loss of data
src\blob.c(638): error C2017: illegal escape sequence
src\blob.c(638): error C2224: left of '.Blob' must have struct/union type
src\blob.c(638): error C2001: newline in constant
src\blob.c(638): error C2059: syntax error: 'string'
error: command 'C:\Program Files (x86)\Microsoft Visual Studio19\BuildTools\VC\Tools\MSVC.28.29333\bin\HostX86\x64\cl.exe' failed with exit code 2

这里是Blob.c中的行(第638行是MODULE_NAME ".Blob",):

PyTypeObject pysqlite_BlobType = {
        PyVarObject_HEAD_INIT(NULL, 0)
        MODULE_NAME ".Blob",
        .tp_basicsize = sizeof(pysqlite_Blob),
        .tp_dealloc = (destructor)pysqlite_blob_dealloc,
        .tp_as_sequence = &blob_sequence_methods,
        .tp_as_mapping = &blob_mapping_methods,
        .tp_flags = Py_TPFLAGS_DEFAULT,
        .tp_weaklistoffset = offsetof(pysqlite_Blob, in_weakreflist),
        .tp_methods = blob_methods,
};

有人可以帮助我继续吗? 谢谢

我今天遇到了同样的问题,设置几乎完全相同。我需要做两个修改才能成功编译 sqlcipher3:

  1. MODULE_NAME预编译器定义的内容设置在setup.py的第38行。此处调用的函数 quote_argument 区分 Windows 和其他平台。在 Windows 上,引号字符使用反斜杠转义。至少对于 MSVC2019,这似乎是不正确的。要修复它,只需删除第 35 行的 Windows-specific 内容。

  2. OpenSSL 的库名称在 1.1.0 版本中发生了变化。如果您使用的是较新的版本,您可能必须将库名称从 libeay32.lib 更改为 libcrypto.lib 或在您的系统上调用的任何库名称(第 132 行)。此外,您可能必须设置环境变量 OPENSSL_CONF,以帮助构建脚本在您的系统上找到 OpenSSL。

通过这两个小修改,构建过程运行良好。