Windows下编译zlib,zstd,openssl,mariadb,pugixml,sqlite3
updated date: 2024-10-30
- zstd 1.5.5 -> 1.5.6
- openssl 3.2.1 -> 3.3.0 -> 3.3.1 -> 3.3.2 -> 3.4.0
- mariadb-c-connect 3.3.8 -> 3.3.10 -> 3.3.11 (3.4.1编译后测试连接数据库失败)
- curl 8.9.1 -> 8.10.1
- sqlite3 3460100 -> 3470000
1. zlib 1.3.1
x86
vs2008编译:
cmake -G “Visual Studio 9 2008” -DCMAKE_INSTALL_PREFIX=/libs ..
编译 v141_xp 兼容:
cmake -G “Visual Studio 16 2019” -A Win32 -DCMAKE_GENERATOR_TOOLSET=v141_xp -DCMAKE_INSTALL_PREFIX=/libs ..
vs2022编译:
cmake -G “Visual Studio 17 2022” -A Win32 -DCMAKE_INSTALL_PREFIX=/libs ..
x64
- vs2022编译:
cmake -G “Visual Studio 17 2022” -DCMAKE_INSTALL_PREFIX=/libs ..
- vs2022编译:
随后进入项目文件夹双击 zlib.sln,将 “C/C++ - 代码生成” 属性页中的运行库改为 “多线程 /MT” 或 “多线程调试 /MTd”,在工具条的 “解决方案配置” 中选择 Release 或 debug 后,在 “解决方案资源管理器” 窗口中的 “解决方案” 点击鼠标右键选择 “生成解决方案”,最后在 “INSTALL” 项目点击鼠标右键选择 “仅用于项目 - 仅生成”
2. zstd 1.5.6
- build/vs2010目录中双击zstd.sln打开vs解决方案,并编译相应版
3. openssl 3.4.0
x86
release版:
set __CNF_LDFLAGS=/NODEFAULTLIB:msvcrt.lib
perl ../../Configure VC-WIN32 –prefix=/libs –openssldir=ssl no-shared zlib no-asm no-async no-dso no-engine enable-ktls enable-rc5 enable-md2 enable-zstd –with-zlib-include=/libs/include –with-zlib-lib=”d:/libs/lib/x86/release/zlibstatic.lib” –with-zstd-include=/libs/include –with-zstd-lib=”d:/libs/lib/x86/release/libzstd_static.lib”
debug版:
set __CNF_LDFLAGS=/NODEFAULTLIB:libcmtd
perl ../../Configure VC-WIN32 –prefix=/libs –openssldir=ssl –debug no-shared zlib no-asm no-async no-dso no-engine enable-ktls enable-rc5 enable-md2 enable-zstd –with-zlib-include=/libs/include –with-zlib-lib=”d:/libs/lib/x86/debug/zlibstaticd.lib” –with-zstd-include=/libs/include –with-zstd-lib=”d:/libs/lib/x86/debug/libzstd_static.lib”
编译 v141_xp 兼容的x86版:
release版:
set __CNF_LDFLAGS=/NODEFAULTLIB:msvcrt.lib
perl ../../Configure VC-WIN32 –prefix=/libs –openssldir=ssl no-shared zlib no-asm no-async no-dso no-engine enable-ktls enable-rc5 enable-md2 enable-zstd –with-zlib-include=/libs/include –with-zlib-lib=”d:/libs/lib/x86/release/zlibstatic.lib” –with-zstd-include=/libs/include –with-zstd-lib=”d:/libs/lib/x86/release/libzstd_static.lib” -D_WIN32_WINNT=0x0501 -D_USING_V110_SDK71_
debug版:
set __CNF_LDFLAGS=/NODEFAULTLIB:libcmtd
perl ../../Configure VC-WIN32 –prefix=/libs –openssldir=ssl –debug no-shared zlib no-asm no-async no-dso no-engine enable-ktls enable-rc5 enable-md2 enable-zstd –with-zlib-include=/libs/include –with-zlib-lib=”d:/libs/lib/x86/debug/zlibstaticd.lib” –with-zstd-include=/libs/include –with-zstd-lib=”d:/libs/lib/x86/debug/libzstd_static.lib” -D_WIN32_WINNT=0x0501 -D_USING_V110_SDK71_
在生成的 makefile 中:
LIB_LDFLAGS 后面添加 /subsystem:windows,5.01 ;
DSO_LDFLAGS 后面添加 /subsystem:windows,5.01 ;
BIN_LDFLAGS 修改 /subsystem:console 为 /subsystem:console,5.01
debug版修改:LIB_CFLAGS中 /MT 为 /MTd
x64
release版:
set __CNF_LDFLAGS=/NODEFAULTLIB:msvcrt.lib
perl ../../Configure VC-WIN64A –prefix=/libs –openssldir=ssl no-shared zlib no-asm no-async no-dso no-engine enable-ktls enable-rc5 enable-md2 enable-zstd –with-zlib-include=/libs/include –with-zlib-lib=”d:/libs/lib/x64/release/zlibstatic.lib” –with-zstd-include=/libs/include –with-zstd-lib=”d:/libs/lib/x64/release/libzstd_static.lib”
debug版:
set __CNF_LDFLAGS=/NODEFAULTLIB:libcmtd
perl ../../Configure VC-WIN64A –prefix=/libs –openssldir=ssl –debug no-shared zlib no-asm no-async no-dso no-engine enable-ktls enable-rc5 enable-md2 enable-zstd –with-zlib-include=/libs/include –with-zlib-lib=”d:/libs/lib/x64/debug/zlibstaticd.lib” –with-zstd-include=/libs/include –with-zstd-lib=”d:/libs/lib/x64/debug/libzstd_static.lib”
编译及安装
nmake
nmake install_sw
4. mariadb c connector 3.3.11
x86
vs2008编译:
cmake -G “Visual Studio 9 2008” -DCMAKE_INSTALL_PREFIX=”/libs” -DPREFIX_INSTALL_DIR=”/libs” -DCMAKE_BUILD_TYPE=RELEASE -DWITH_OPENSSL=ON -DWITH_MYSQLCOMPAT=OFF -DWITH_EXTERNAL_ZLIB=ON -DZLIB_LIBRARY=”/libs/lib/x86/release/zlibstatic.lib” -DZLIB_INCLUDE_DIR=”/libs/include” -DZLIB_LIBRARIES=”/libs/lib/x86/release/zlibstatic.lib” -DZSTD_INCLUDE_DIRS=”/libs/include” -DZSTD_LIBRARIES=”/libs/lib/x86/release/libzstd_static.lib” ..
编译 v141_xp 兼容:
修改 cmake\ConnectorName.cmake 第 25 行 “END” 为 “ENDIF”;cmake -G “Visual Studio 16 2019” -A Win32 -DCMAKE_GENERATOR_TOOLSET=v141_xp -DCMAKE_INSTALL_PREFIX=”/libs” -DPREFIX_INSTALL_DIR=”/libs” -DCMAKE_BUILD_TYPE=Release -DWITH_SSL=ON -DWITH_MYSQLCOMPAT=OFF -DWITH_EXTERNAL_ZLIB=ON -DZLIB_LIBRARY=”/libs/lib/x86/release/zlibstatic.lib” -DZLIB_INCLUDE_DIR=”/libs/include” -DZLIB_LIBRARIES=”/libs/lib/x86/release/zlibstatic.lib” -DZSTD_INCLUDE_DIRS=”/libs/include” -DZSTD_LIBRARIES=”/libs/lib/x86/release/libzstd_static.lib” ..
vs2022编译
cmake -G “Visual Studio 17 2022” -A Win32 -DCMAKE_INSTALL_PREFIX=”/libs” -DPREFIX_INSTALL_DIR=”/libs” -DCMAKE_BUILD_TYPE=Release -DWITH_SSL=ON -DWITH_MYSQLCOMPAT=OFF -DWITH_EXTERNAL_ZLIB=ON -DZLIB_LIBRARY=”/libs/lib/x86/release/zlibstatic.lib” -DZLIB_INCLUDE_DIR=”/libs/include” -DZLIB_LIBRARIES=”/libs/lib/x86/release/zlibstatic.lib” -DZSTD_INCLUDE_DIRS=”/libs/include” -DZSTD_LIBRARIES=”/libs/lib/x86/release/libzstd_static.lib” -DWITH_CURL=ON -DCURL_INCLUDE_DIR=”/libs/include/curl” -DCURL_LIBRARY=”/libs/lib/x86/release/libcurl.lib” ..
x64
vs2008编译:
cmake -G “Visual Studio 9 2008 Win64” -DCMAKE_INSTALL_PREFIX=”/libs” -DPREFIX_INSTALL_DIR=”/libs” -DCMAKE_BUILD_TYPE=RELEASE -DWITH_OPENSSL=ON -DWITH_MYSQLCOMPAT=OFF -DWITH_EXTERNAL_ZLIB=ON -DZLIB_LIBRARY=”/libs/lib/x64/release/zlibstatic.lib” -DZLIB_INCLUDE_DIR=”/libs/include” -DZLIB_LIBRARIES=”/libs/lib/x64/release/zlibstatic.lib” -DZSTD_INCLUDE_DIRS=”/libs/include” -DZSTD_LIBRARIES=”/libs/lib/x64/release/libzstd_static.lib” ..
vs2022编译:
cmake -G “Visual Studio 17 2022” -DCMAKE_INSTALL_PREFIX=”/libs” -DPREFIX_INSTALL_DIR=”/libs” -DCMAKE_BUILD_TYPE=Release -DWITH_SSL=ON -DWITH_MYSQLCOMPAT=OFF -DWITH_EXTERNAL_ZLIB=ON -DZLIB_LIBRARY=”/libs/lib/x64/release/zlibstatic.lib” -DZLIB_INCLUDE_DIR=”/libs/include” -DZLIB_LIBRARIES=”/libs/lib/x64/release/zlibstatic.lib” -DZSTD_INCLUDE_DIRS=”/libs/include” -DZSTD_LIBRARIES=”/libs/lib/x64/release/libzstd_static.lib” -DWITH_CURL=ON -DCURL_INCLUDE_DIR=”/libs/include/curl” -DCURL_LIBRARY=”/libs/lib/x64/release/libcurl.lib” ..
编译及安装
cmake –build . –config Release以下在vs2008中需要,vs2019不需要操作
修改 libmariadb\my_pthread.c 中 ETIMEDOUT 为 WSAETIMEDOUT
修改 libmariadb\libmariadb.c 中 ETIMEDOUT 为 WSAETIMEDOUT
修改 libmariadb\violite.c 中 ETIMEDOUT 为 WSAETIMEDOUT 并注释 #define SOCKET_EWOULDBLOCK SOCKET_EAGAIN如果需要分别编译debug版与release版的话,最好根据不同版的输入链接库分别生成相应的解决方案
随后进入项目文件夹双击 mariadb-connector-c.sln,将 “C/C++ - 代码生成” 属性页中的运行库改为 “多线程 /MT” 或 “多线程调试 /MTd”,在工具条的 “解决方案配置” 中选择 Release 或 debug 后,在 “解决方案资源管理器” 窗口中的 “解决方案” 点击鼠标右键选择 “生成解决方案”,最后在 “INSTALL” 项目点击鼠标右键选择 “仅用于项目 - 仅生成”
5. pugixml 1.14
在 CMakeLists.txt 中添加 “add_definitions(-DUNICODE -D_UNICODE)” 使生成的项目方案默认使用 unicode 字符
- x86
vs2008编译:
cmake -G “Visual Studio 9 2008” -DCMAKE_INSTALL_PREFIX=/libs ..
编译 v141_xp 兼容:
cmake -G “Visual Studio 16 2019” -A Win32 -DCMAKE_GENERATOR_TOOLSET=v141_xp -DCMAKE_INSTALL_PREFIX=/libs ..
vs2022编译:
cmake -G “Visual Studio 17 2022” -A Win32 -DCMAKE_INSTALL_PREFIX=/libs ..
- x64
vs2008编译:
cmake -G “Visual Studio 9 2008 Win64” -DCMAKE_INSTALL_PREFIX=/libs ..
vs2022编译:
cmake -G “Visual Studio 17 2022” -DCMAKE_INSTALL_PREFIX=/libs ..
- 编译及安装
随后进入项目文件夹双击 pugixml.sln,将 “C/C++ - 代码生成” 属性页中的运行库改为 “多线程 /MT” 或 “多线程调试 /MTd”,在工具条的 “解决方案配置” 中选择 Release 或 debug 后,在 “解决方案资源管理器” 窗口中的 “解决方案” 点击鼠标右键选择 “生成解决方案”,最后在 “INSTALL” 项目点击鼠标右键选择 “仅用于项目 - 仅生成”
6. curl 8.10.1
进入winbuild下
- x86
- release版
nmake /f Makefile.vc mode=static VC=17 MACHINE=x86 DEBUG=no
- debug版
nmake /f Makefile.vc mode=static VC=17 MACHINE=x86 DEBUG=yes
- release版
- x64
- release版
nmake /f Makefile.vc mode=static VC=17 MACHINE=x64 DEBUG=no
- debug版
nmake /f Makefile.vc mode=static VC=17 MACHINE=x64 DEBUG=yes
mode=static,编译静态库。mode=dll,编译动态库
- release版
7. sqlite3 3470000
- 编译静态库
sqlite官网中分别下载sqlite-amalgamation-3470000.zip与sqlite-dll-win-x64-3470000.zip文件,并分别解压
vs 2022下创建空的方案,并在空的方案下新建新的空白工程项目,将shell.c、sqlite3.c、sqlite3.h、sqlite3ext.h加入到工程项目中
在该工程项目右键鼠标,选择”Properties” -> “C/C++” -> “Preprocessor” -> “Preprocessor Definitions”设置预定义处理
_USRDLL
SQLITE_ENABLE_RTREE
SQLITE_ENABLE_COLUMN_METADATA
SQLITE_ENABLE_FTS5
SQLITE_ENABLE_UNLOCK_NOTIFY修改模块定义文件sqlite3.def,在最后追加sqlite3_unlock_notify
在该工程项目右键鼠标,选择”Properties” -> “Linker” -> “Input” -> “Module Definition File”中添加sqlite3.def
在该工程项目右键鼠标,选择”Properties” -> “General” -> “Confiuration Type”修改为”Static library (.lib)”
在该工程项目右键鼠标,选择”Properties” -> “C/C++” -> “Code Generation” -> “Runtime Library”中按Debug与Release分别修改为”Multi-threaded DLL (/MTd)”与”Multi-threaded (/MT)”
- 编译动态库
前面2步骤同编译静态库
在该工程项目右键鼠标,选择”Properties” -> “C/C++” -> “Preprocessor” -> “Preprocessor Definitions”设置预定义处理
SQLITE_ENABLE_FTS3
SQLITE_ENABLE_FTS5
SQLITE_ENABLE_RTREE
SQLITE_ENABLE_GEOPOLY
SQLITE_ENABLE_DBPAGE_VTAB
SQLITE_ENABLE_DBSTAT_VTAB
SQLITE_ENABLE_BYTECODE_VTAB
SQLITE_ENABLE_COLUMN_METADATA
SQLITE_ENABLE_SESSION
SQLITE_ENABLE_PREUPDATE_HOOK
SQLITE_ENABLE_MATH_FUNCTIONS
SQLITE_ENABLE_RBU
SQLITE_OMIT_SEH
SQLITE_ENABLE_FTS4
SQLITE_SYSTEM_MALLOC
SQLITE_OMIT_LOCALTIME
SQLITE_ENABLE_UNLOCK_NOTIFY
SQLITE_ENABLE_STMTVTAB
SQLITE_ENABLE_EXPLAIN_COMMENTS
SQLITE_ENABLE_OFFSET_SQL_FUNC
SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
SQLITE_ENABLE_STMT_SCANSTATUS
SQLITE_STRICT_SUBTYPE
SQLITE_DQS后面2步骤同编译静态库
在该工程项目右键鼠标,选择”Properties” -> “General” -> “Confiuration Type”修改为”Dynamic Library (.dll)”
在该工程项目右键鼠标,选择”Properties” -> “C/C++” -> “Code Generation” -> “Runtime Library”中按Debug与Release分别修改为”Multi-threaded DLL (/MTd)”与”Multi-threaded (/MT)”