C++ libcurl错误,curl_easy_perform()失败:c++;

C++ libcurl错误,curl_easy_perform()失败:c++;,c++,curl,libcurl,C++,Curl,Libcurl,我编写了以下代码,用于使用libcurl下载文件: #ifndef CHECK_RESOURCES_H #define CHECK_RESOURCES_H #include <string> #include <stdio.h> #include <curl/curl.h> // #include <bzlib.h> void progress_bar (void* ptr, double TotalToDownload, double No

我编写了以下代码,用于使用libcurl下载文件:

#ifndef CHECK_RESOURCES_H
#define CHECK_RESOURCES_H

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


void progress_bar (void* ptr, double TotalToDownload, double NowDownloaded, \
    double TotalToUpload, double NowUploaded) {

    printf("%f : %f \n", TotalToDownload, NowDownloaded);
}

void download_file () {
    CURL *curl;
    CURLcode res;
    char outFileName[FILENAME_MAX] = "shape_predictor_68_face_landmarks.dat.bz2";
    std::string url = "http://ufpr.dl.sourceforge.net/project/dclib/dlib/v18.10/shape_predictor_68_face_landmarks.dat.bz2";
    FILE *fp;

    curl = curl_easy_init ();
    if (curl) {
        fp = fopen (outFileName, "wb");

        curl_easy_setopt (curl, CURLOPT_URL, url.c_str());
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);

        // Internal CURL progressmeter must be disabled if we provide our own callback
        curl_easy_setopt(curl, CURLOPT_NOPROGRESS, false);
        // Install the callback function
        curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_bar);

        res = curl_easy_perform (curl);

        if (res != CURLE_OK) {
            fprintf(stderr, "%s%s\n", "curl_easy_perform() failed : ", curl_easy_strerror(res));
        }

        curl_easy_cleanup (curl);
        fclose (fp);
    }
}

void extract_bz2 () {

}


void check_dlib_landmark_weights (const std::string& name) {
    if (FILE *file = fopen(name.c_str(), "r")) {
        fclose(file);
    } else {
        download_file ();
    }
}


#endif  // CHECK_RESOURCES_H

我不明白这为什么会失败。我已经检查了我正在使用的链接,它是一个工作链接(下载的文件没有任何问题)。如何更正此问题?

函数
CURLOPT\u PROGRESSFUNCTION
期望回调函数返回值0,当前函数返回void。如果修改
progress\u bar
函数以返回
int
,而不是
void
,并添加
返回0到最后应该可以解决问题。

如果您不提供自己的回调,会发生什么?如果我不提供进度条,它将继续下载
0.000000 : 0.000000 
0.000000 : 0.000000 
curl_easy_perform() failed : Operation was aborted by an application callback