我正在使用 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/