深度Linux下编译curl支持https

1.安装:sudo  apt-get install openssl

2.安装:sudo apt-get install libssl-dev

本文用的curl版本为curl-7.54.0

curl下载地址为:https://curl.haxx.se/download/

3.在命令行里运行:./configure --prefix=/usr/local/bin/curl --with-ssl

4.在命令行里运行:make

5.在命令行里运行:make install

测试是否支持https:

#include "curl/curl.h"

int main()
{
    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();
    if(curl) {
      curl_easy_setopt(curl, CURLOPT_URL, "https://www.baidu.com");
      /* example.com is redirected, so we tell libcurl to follow redirection */
      curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

      /* Perform the request, res will get the return code */
      res = curl_easy_perform(curl);
      /* Check for errors */
      if(res != CURLE_OK)
        fprintf(stderr, "curl_easy_perform() failed: %s\n",
                curl_easy_strerror(res));

      /* always cleanup */
      curl_easy_cleanup(curl);
    }

}

运行后结果为:

深度Linux下编译curl支持https

这表示curl编译成功。

运行结果如下所示表示不支持https

深度Linux下编译curl支持https