如何获取和比较libcurl版本? [英] How to get and compare libcurl version?

查看:845
本文介绍了如何获取和比较libcurl版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用libcurl设置OAuth 2.0访问令牌.从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 );,但是我不知道struct中的数据如何以及如何将它们与7.33版本进行比较. 有人可以帮我吗?

I am using libcurl setting OAuth 2.0 access token. Since libcurl 7.33 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_XOAUTH2_BEARER, char *token); option was added. Now I need to get the libcurl version and compare it with 7.33. In case where version is 7.33 or higher I will use CURLOPT_XOAUTH2_BEARER otherwise I will do something else. I know I should somehow use curl_version_info_data *curl_version_info( CURLversion type ); but I have no idea, how the data in struct look like and how to compare them to 7.33 version. Can someone help me?

推荐答案

如果要在运行时检测版本,可以使用

If you want to detect version at run-time, you can use curl_version_info() in a style like this:

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表达式,如下所示:

If you prefer to do the detection build-time, you can use a preprocessor #if expression like this:

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

这篇关于如何获取和比较libcurl版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆