gpt4 book ai didi

c - 如何检查宏是否可用

转载 作者:行者123 更新时间:2023-11-30 19:02:44 26 4
gpt4 key购买 nike

我试图查看我的 libcurl 是否支持 CURLSSLBACKEND_OPENSSL,但迷路了。如何判断是否设置了宏?完成此任务的正确方法是什么?

代码如下:

#include <stdio.h>
#include <curl/curl.h>

int main(){
printf("CURLSSLBACKEND_OPENSSL is %d\n", CURLSSLBACKEND_OPENSSL);

#if (CURLSSLBACKEND_OPENSSL == 1)
puts("CURLSSLBACKEND_OPENSSL is 1");
#else
puts("CURLSSLBACKEND_OPENSSL is NOT 1");
#endif

#ifndef CURLSSLBACKEND_OPENSSL
#define CURLSSLBACKEND_OPENSSL 0
#endif
printf("CURLSSLBACKEND_OPENSSL is %d\n", CURLSSLBACKEND_OPENSSL);


#ifdef meh
printf("meh is defined!\n");
#else
printf("meh is NOT defined!\n");
#endif
return 0;
}

这是输出,它是错误的:

 $ ./a.out
CURLSSLBACKEND_OPENSSL is 1
CURLSSLBACKEND_OPENSSL is NOT 1 // <-- wrong
CURLSSLBACKEND_OPENSSL is 0 // <-- nope..
meh is NOT defined!

任何建议将不胜感激,提前致谢!

最佳答案

感谢您的指点,给我发了right方式。

我的代码已修改如下:

curl_version_info_data  *curl_version_data;
+#if LIBCURL_VERSION_NUM >= 0x073800
+ if (curl_version_data->version_num >= 0x073800){
+ printf("Setting CURLSSLBACKEND_OPENSSL\n");
+ CURLsslset result;
+ result = curl_global_sslset((curl_sslbackend)1, NULL, NULL);
+ assert(result == CURLSSLSET_OK);
+ } else {
+ printf("libcurl version too old to set CURLSSLBACKEND_OPENSSL\n");
+ }
+#else
+#warning "libcurl version too old to set CURLSSLBACKEND_OPENSSL"
+ printf("libcurl version too old to set CURLSSLBACKEND_OPENSSL\n");
+#endif
+
+

它似乎正在做我最初的意图。

关于c - 如何检查宏是否可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55482866/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com