GMSSL在windows下使用vs2010编译

GMSSL简介

项目主页:http://gmssl.org/
github:https://github.com/guanzhi/GmSSL

GMSSL windows + vs2010 编译

编译和安装:http://gmssl.org/docs/install.html
Windows下编译如下:
编译命令

编译错误

1. base58.c error C2057: 应输入常量表达式
报错如下:
crypto\base58\base58.c(81) : error C2057: 应输入常量表达式
crypto\base58\base58.c(81) : error C2466: 不能分配常量大小为 0 的数组
crypto\base58\base58.c(81) : error C2133: “outi”: 未知的大小

报错代码为:

int base58_decode(const char *b58, size_t b58sz, void *bin, size_t *binszp)
{
    size_t binsz = *binszp;
    const unsigned char *b58u = (void*)b58;
    unsigned char *binu = bin;
    size_t outisz = (binsz + 3) / 4;
    uint32_t outi[outisz];
    uint64_t t;
    uint32_t c;
    size_t i, j;

解决方法:
vs不支持使用变量定义数组大小,所以将outi改为使用malloc分配即可。

int base58_decode(const char *b58, size_t b58sz, void *bin, size_t *binszp)
{
    size_t binsz = *binszp;
    const unsigned char *b58u = (void*)b58;
    unsigned char *binu = bin;
    size_t outisz = (binsz + 3) / 4;
    uint32_t *outi = (uint32_t *)malloc(outisz);//改为malloc
    uint64_t t;
    uint32_t c;
    size_t i, j;

2. base58.c : error C2065: “ssize_t”: 未声明的标识符
报错如下:
crypto\base58\base58.c(173) : error C2065: “ssize_t”: 未声明的标识符
crypto\base58\base58.c(173) : error C2146: 语法错误: 缺少“;”(在标识符“i”的前面)
报错代码为:

int base58_encode(const void *data, size_t binsz, char *b58, size_t *b58sz)
{
    const uint8_t *bin = data;
    int carry;
    ssize_t i, j, high, zcount = 0;

解决方法:
ssize_t定义在BaseTsd.h中,该文件在Windows SDK目录中,在base58.c中引入该头文件即可。

#if defined(_MSC_VER)
#include <BaseTsd.h>
#endif

3.base58.c error C2275: “uint8_t”: 将此类型用作表达式非法
报错如下:
crypto\base58\base58.c(185) : error C2275: “uint8_t”: 将此类型用作表达式非法

报错代码为:

int base58_encode(const void *data, size_t binsz, char *b58, size_t *b58sz)
{
    const uint8_t *bin = data;
    int carry;
    ssize_t i, j, high, zcount = 0;
    size_t size;

    while (zcount < binsz && !bin[zcount])
        ++zcount;

    size = (binsz - zcount) * 138 / 100 + 1;
    uint8_t buf[size];
    memset(buf, 0, size);

解决方法:
vs不支持使用变量定义数组大小,所以buf改为malloc分配
由于c语言中,变量的声明要放在函数起始位置,所以将buf声明放到函数开始

int base58_encode(const void *data, size_t binsz, char *b58, size_t *b58sz)
{
    const uint8_t *bin = data;
    unsigned char *buf = NULL;
    int carry;
    ssize_t i, j, high, zcount = 0;
    size_t size;

    while (zcount < binsz && !bin[zcount])
        ++zcount;

    size = (binsz - zcount) * 138 / 100 + 1;
    buf = (unsigned char *)malloc(size);//改为malloc

4.ffx.c fatal error C1083: 无法打开包括文件:“inttypes.h”: No such file or directory
解决方法:
参考这篇文章

将下载的inttypes.h放到ffx.c同目录并将引用改为引号

#include <stdio.h>
#include <ctype.h>
#include <string.h>
//#include <inttypes.h>
#include "inttypes.h"

5.saf_ec.c(94) : error C2275: “EVP_PKEY_CTX”: 将此类型用作表达式非法
凡是遇到将此类型用作表达式非法的错误都是因为变量的生命没有放到函数开始处
解决方法:
将声明放到函数开始出即可

6.error LNK2001: 无法解析的外部符号 speck_expand16
报错如下:
libcrypto-1_1.def : error LNK2001: 无法解析的外部符号 speck_expand16
libcrypto-1_1.def : error LNK2001: 无法解析的外部符号 speck_expand32
libcrypto-1_1.def : error LNK2001: 无法解析的外部符号 speck_expand64
libcrypto.lib : fatal error LNK1120: 3 个无法解析的外部命令

解决方法:
将include\openssl\speck.h中speck_expand16,speck_expand32,speck_expand64的声明删除
执行 perl util/mkdef.pl crypto update重新生成libcrypto.num

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 15
    评论
以下是在 Windows 平台下使用 Visual Studio 2017 编译 Ghostscript 库的步骤: 1. 下载 Ghostscript 源代码 你可以在 Ghostscript 官网的下载页面 [https://www.ghostscript.com/download/gsdnld.html](https://www.ghostscript.com/download/gsdnld.html) 上下载 Ghostscript 的源代码。下载完成后,解压到本地。 2. 安装依赖库 Ghostscript 依赖以下库: - zlib - libpng - jpeglib - tiff 你可以在各自的官网上下载这些库的源代码,或者使用编译的二进制文件。 3. 配置编译环境 - 安装 Visual Studio 2017,并安装 C++ 开发环境。 - 安装 CMake。你可以从 [https://cmake.org/download/](https://cmake.org/download/) 下载最新版本的 CMake。 4. 生成 Visual Studio 工程 - 打开 CMake GUI。 - 在 "Where is the source code" 中填写 Ghostscript 源代码的路径。 - 在 "Where to build the binaries" 中填写生成的工程文件路径,例如 Ghostscript/build。 - 点击 Configure,选择 Visual Studio 版本并选择生成 64 位库。 - CMake 会提示你输入各种选项,你可以根据自己的需求进行选择。如果不确定,可以选用默认值。 - 点击 Generate,CMake 会生成 Visual Studio 工程文件。 5. 编译 Ghostscript 库 - 打开 Visual Studio,打开生成的 Ghostscript 工程文件。 - 在解决方案栏中,右键点击 ALL_BUILD 项目,选择生成。 - 编译完成后,在解决方案栏中找到 gs 工程,右键点击 INSTALL 项目,选择生成。 - 编译完成后,你可以在 Ghostscript 安装目录下找到生成的库文件。 以上就是在 Windows 平台下使用 Visual Studio 2017 编译 Ghostscript 库的步骤。希望对你有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雷动软件工作室

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值