Gmssl windows下编译

第一步:确认终端环境

打开开始菜单 → MSYS2 UCRT64,执行:

复制代码
echo $MSYSTEM
which gcc

输出必须:

复制代码
UCRT64
/ucrt64/bin/gcc

第二步:安装 UCRT64 配套全套工具(UCRT64 终端内执行)

复制代码
pacman -Syu

如果提示关闭终端,关掉,重新打开 UCRT64 继续。

复制代码
pacman -S mingw-w64-ucrt-x86_64-toolchain mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-make git

验证工具:

复制代码
gcc --version
mingw32-make --version
cmake --version

全部正常输出版本号。

第三步:编译 GmSSL‑3(UCRT64 完整命令)

复制代码
git clone https://github.com/guanzhi/GmSSL.git
cd GmSSL
git checkout tags/v3.2.0

mkdir build_ucrt64
cd build_ucrt64

若提醒连接不到github,可手动下载工程。

在CMakeLists.txt中,找到第229行 附近的add_executable(gmssl-bin ${tools}),用条件判断包起来:

复制代码
# 替换第229-232行
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
    add_executable(gmssl-bin ${tools})
    target_link_libraries(gmssl-bin LINK_PUBLIC gmssl)
    set_target_properties(gmssl-bin PROPERTIES RUNTIME_OUTPUT_NAME gmssl)
    if (WIN32)
        target_link_libraries(gmssl-bin PRIVATE Ws2_32)
    endif()
    # ... 后面的测试相关代码也包在这个if块里 ...
endif()

改成:

复制代码
# 新增一个option,默认ON表示构建命令行工具
option(BUILD_GMSSL_BIN "Build gmssl command-line tool" ON)

if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "iOS" AND BUILD_GMSSL_BIN)
    add_executable(gmssl-bin ${tools})
    target_link_libraries(gmssl-bin LINK_PUBLIC gmssl)
    set_target_properties(gmssl-bin PROPERTIES RUNTIME_OUTPUT_NAME gmssl)
    if (WIN32)
        target_link_libraries(gmssl-bin PRIVATE Ws2_32)
    endif()
    # ... 后面的测试代码也包在这个if块里 ...
endif()

编译命令为:

复制代码
cmake .. -G "Unix Makefiles" \
-DBUILD_SHARED_LIBS=OFF \
-DENABLE_COMMAND_LINE=OFF \
-DENABLE_TEST=OFF \
-DENABLE_DLOPEN=OFF \
-DBUILD_GMSSL_BIN=OFF

编译:

复制代码
make -j4

然后可以正常编译输出静态链接库文件。

相关推荐
kakakahahahaha4 小时前
Win10开始菜单打不开排查:explorer、AppX注册、SFC、服务与用户配置修复
windows·电脑·笔记本电脑·内容运营·软件需求
ITHAOGE154 小时前
下载 | Windows Server 2016最新纯净版ISO映像!(集成9月更新、标准版、数据中心版、14393.9514)
windows·科技·微软·电脑
传奇开心果编程10 小时前
【Compose Multiplatform 跨端开发学与练】第3课 布局与组件
android·windows·学习·ui·ios·kotlin·composer
懒人811 小时前
Windows11系统优化指南
windows·经验分享
Vex2une11 小时前
Windows 磁盘管理发展史:从 FDISK 分区表到存储池与虚拟磁盘
windows·gpt·磁盘管理·mbr·fdisk·动态磁盘·储存池
今夕资源网11 小时前
从夯到拉模拟器RankPix windows本地版 exe
windows·exe·从夯到拉·从夯到拉模拟器·rankpix·本地版
kakakahahahaha12 小时前
Windows系统时间校准指南:time命令、date命令、w32tm /resync与CMOS排查
windows·笔记本电脑·软件需求
一技安身13 小时前
【mysql】Windows MySQL 8.4.10 绿色免安装喂饭教程
windows·mysql·adb
传奇开心果编程13 小时前
【Compose Multiplatform 跨端开发学与练】第8课 资源管理与主题
android·windows·学习·ios·kotlin·web·composer
sukalot14 小时前
Windows 驱动实例分析系列:libwdi 驱动分析 - 应用篇(一)
windows·驱动开发