curl编译:error: call to ‘_curl_easy_setopt_err_curl_off_t‘

在使用curl库时遇到了一个编译错误,错误指出调用_curl_easy_setopt_err_curl_off_t函数时参数类型不匹配。解决方案是,在32位系统中将downloadedSize定义为longlong类型,而在64位系统中定义为long类型,以确保与curl_easy_setopt期望的curl_off_t类型兼容。
inc/curl/typecheck-gcc.h:50:13: error: call to '_curl_easy_setopt_err_curl_off_t' declared with attribute warning: curl_easy_setopt expects a curl_off_t argument for this option [-Werror]
             _curl_easy_setopt_err_curl_off_t();                         \
             ^
curlDemo.c:453:5: note: in expansion of macro 'curl_easy_setopt'
     curl_easy_setopt(curl, CURLOPT_RESUME_FROM_LARGE, downloadedSize);

解决方法:

32位 downloadedSize定义为long long 类型

64位 downloadedSize 定义为long 类型

int delete_by_time_range(const char* start, const char* stop, const char* predicate, char* error_msg, size_t err_size) { CURL *curl = curl_easy_init(); if (!curl) { snprintf(error_msg, err_size, "CURL 初始化失败"); return 0; } char url[512]; snprintf(url, sizeof(url), "%s/api/v2/delete?bucket=%s&org=%s", HOST, BUCKET, ORG); const char* pred_expr = predicate ? predicate : "_measurement=\"%s\""; char json_payload[1024]; snprintf(json_payload, sizeof(json_payload), "{\"start\": \"%s\", \"stop\": \"%s\", \"predicate\": \"%s\"}", start, stop, pred_expr); struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "Content-Type: application/json"); char auth_header[512]; snprintf(auth_header, sizeof(auth_header), "Authorization: Token %s", TOKEN); headers = curl_slist_append(headers, auth_header); struct MemoryStruct resp; init_memory(&resp); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json_payload); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &resp); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30); int success = 0; CURLcode res = curl_easy_perform(curl); if (res != CURLE_OK) { snprintf(error_msg, err_size, "Delete 请求失败: %s", curl_easy_strerror(res)); } else { long status; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status); if (status == 204) { success = 1; } else { snprintf(error_msg, err_size, "Delete 失败: HTTP %ld, 响应: %.200s", status, resp.memory); } } curl_slist_free_all(headers); curl_easy_cleanup(curl); free_memory(&resp); return success; } 以上代码执行时提示{"code":"invalid","message":"error decoding json body: invalid character 'l' after object key:value pair"}
09-20
/** * @brief 删除指定时间点附近的一个极小时间段内的数据 * @param iso_time ISO8601 时间字符串(如 2024-01-01T00:00:00Z) * @param error_msg 错误信息缓冲区 * @param err_size 缓冲区大小 * @return 成功返回 1;失败返回 0 */ int delete_at_timestamp(const char* iso_time, char* error_msg, size_t err_size) { CURL *curl = curl_easy_init(); if (!curl) { snprintf(error_msg, err_size, "CURL 初始化失败"); return 0; } char url[512]; snprintf(url, sizeof(url), "%s/api/v2/delete?bucket=%s&org=%s", HOST, BUCKET, ORG); char json_payload[1024]; snprintf(json_payload, sizeof(json_payload), "{\"start\": \"%s\", \"stop\": \"%s.000000001Z\", \"predicate\": \"_measurement=\\\"%s\\\"\"}", iso_time, iso_time, MEASUREMENT); struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "Content-Type: application/json"); char auth_header[512]; snprintf(auth_header, sizeof(auth_header), "Authorization: Token %s", TOKEN); headers = curl_slist_append(headers, auth_header); struct MemoryStruct response; init_memory(&response); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json_payload); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30); int success = 0; CURLcode res = curl_easy_perform(curl); if (res != CURLE_OK) { snprintf(error_msg, err_size, "Delete 请求失败: %s", curl_easy_strerror(res)); } else { long status; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status); if (status == 204) { success = 1; } else { snprintf(error_msg, err_size, "Delete 失败: HTTP %ld, 响应: %.200s", status, response.memory); } } curl_slist_free_all(headers); curl_easy_cleanup(curl); free_memory(&response); return success; }重构为Flux语句实现
09-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值