c - 如何获取和比较 libcurl 版本?

标签 c version libcurl

我正在使用 libcurl 设置 OAuth 2.0 访问 token 。自 libcurl 7.33 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_XOAUTH2_BEARER, char *token); 添加选项。现在我需要获取 libcurl 版本并将其与 7.33 进行比较。如果版本是 7.33 或更高,我将使用 CURLOPT_XOAUTH2_BEARER 否则我将做其他事情。 我知道我应该以某种方式使用 curl_version_info_data *curl_version_info( CURLversion type ); 但我不知道结构中的数据如何以及如何将它们与 7.33 版本进行比较。 有人可以帮助我吗?

最佳答案

如果你想在运行时检测版本,你可以使用curl_version_info () 的样式如下:

curl_version_info_data *d = curl_version_info(CURLVERSION_NOW);

/* compare with the 24 bit hex number in 8 bit fields */
if(d->version_num >= 0x072100) {
  /* this is libcurl 7.33.0 or later */
  printf("Succcess\n");
}
else {
  printf("A too old version\n");
}

如果你更喜欢在构建时进行检测,你可以使用像这样的预处理器#if 表达式:

#include <curl/curl.h>
#if LIBCURL_VERSION_NUM >= 0x072100
 /* this is 7.33.0 or later */
#else
 /* work-around for older libcurls */
#endif

关于c - 如何获取和比较 libcurl 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30233344/

相关文章:

c++ - 在 libcurl ssl 请求中发送客户端证书时遇到问题,我缺少什么?

C中while循环中的逗号分隔表达式

c - 将 sprintf 的十六进制输出保存到 C 中的文件中

maven-2 - 从 Maven 存储库复制工件的最新版本

readClipboard 从 utils 包中删除?

objective-c - Cocoa Objective-C 主循环

c# - libcurl .NET 不想在 Win64 上工作

c - 打印一个整数

c - 从/dev/ttyACM0 读取时出现段错误

java - 奇数和偶数 Java 更新之间有什么区别?