C++ ,编译 阿里云 sdk

发布时间 2023-05-16 17:22:54作者: 曦花

参考 https://help.aliyun.com/document_detail/464171.html?spm=a2c4g.453353.0.0.81fb6cf0iySGZT
要引用 aliyun-openapi-cpp-sdk,包,就必须git clone下源码,并且cmake-gui,编译。

1、一开始反复用谷歌下载 cmake-gui  :Download | CMake,Binary distributions:中的msi格式(可以不用配置,zip需要自己配置)
总是下载失败,显示,失败,需要权限(耽误了不少时间)。
查了之后,不用谷歌浏览器下载,用普通的IE 浏览器,(Microsoft Edge浏览器)。完全可以下载成功。

 

2、网页地址方法下载源码完毕之后,发现,根据https://github.com/aliyun/aliyun-openapi-cpp-sdk/blob/master/README-CN.md

不用安装perl
我发现我电脑有git-bash.exe
就直接按照步骤2运行下载。
【1】运行git-bash.exe,

git clone https://github.com/aliyun/aliyun-openapi-cpp-sdk.git

===============================================================

================================================================

一切准备就绪后,
先安装CMake,根据上图的步骤设置,

在aliyun-openapi-cpp-sdk下新建 build文件夹。
然后选择source和build之后,
点configure,配置vs

就会生成sln

cwarning没有问题,编译是成功的。

注意 BUILD_PRODUCT,后的参数,是 aliyun-openapi-cpp-sdk中的文件夹名字,这里想用 imagerecog的lib和include

如果想重新配置confige,点【File】下的Delete Cache

 

 

这个时候,build下就有一个.sln文件.
打开。编译,却又有如下错误

4>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\wincrypt.h(380,29): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
4>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\wincrypt.h(380,19): error C2146: 语法错误: 缺少“;”(在标识符“HCRYPTPROV”的前面)
4>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\wincrypt.h(899,17): error C3646: “dwVersion”: 未知重写说明符
4>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\wincrypt.h(899,26): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
4>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\wincrypt.h(901,13): error C2143: 语法错误: 缺少“;”(在“*”的前面)
4>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\wincrypt.h(901,13): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
4>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\wincrypt.h(901,19): error C2238: 意外的标记位于“;”之前
4>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\wincrypt.h(902,13): error C3646: “cbOID”: 未知重写说明符
等等,

需改方法:

#ifdef _WIN32
#include <windows.h>
#include <wincrypt.h>
#else
#include <openssl/hmac.h>
#endif

 

将#include <windows.h>放在 #include <wincrypt.h>之前。