前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CentOS8中源码安装libcurl库

CentOS8中源码安装libcurl库

作者头像
ccf19881030
发布2022-05-11 10:40:16
2.4K0
发布2022-05-11 10:40:16
举报
文章被收录于专栏:ccf19881030的博客

CentOS8中源码安装libcurl库

CentOS8中源码安装libcurl库

一、下载libcurl源代码

首先下载libcurl的源代码,可以从github中下载:

代码语言:javascript
复制
    git clone https://github.com/curl/curl.git

或者直接下载最新的libcurl源代码:curl-7.82.0.tar.gz

二、编译构建libcurl库

1、方式一:使用configure和make构建

参考了centos 7.6 源码编译curl 7.75.0curl安装时出现:configure: error: select TLS backend(s) or disable TLS with --without-ssl.这两篇博客, 由于libcurl源代码目录没有提供configure文件,所以要使用buildconf脚本生成对应的configure文件,步骤如下: 1)、安装automake、autoreconf、libtool工具,执行如下命令:

代码语言:javascript
复制
	yum instal autoconf automake libtool -y

2)、执行./buildconf生成configure文件,如下图所示:

有了configure文件,本来以为就可以顺利的执行通常的以下3个步骤就可以了: A、./configure --prefix=/usr B 、make C、make install 没想到执行./configure --prefix=/usr后提示报错了:

代码语言:javascript
复制
[root@iZuf6dcz9uks38gipvu9vhZ curl]# ./configure --prefix=/usr
configure: loading site script /usr/share/config.site
checking whether to enable maintainer-specific portions of Makefiles... no
checking whether make supports nested variables... yes
checking whether to enable debug build options... no
checking whether to enable compiler optimizer... (assumed) yes
checking whether to enable strict compiler warnings... no
checking whether to enable compiler warnings as errors... no
checking whether to enable curl debug memory tracking... no
checking whether to enable hiding of library internal symbols... yes
checking whether to enable c-ares for DNS lookups... no
checking whether to disable dependency on -lrt... (assumed no)
checking whether to enable ECH support... no
checking for path separator... :
checking for sed... /usr/bin/sed
checking for grep... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ar... /usr/bin/ar
checking for a BSD-compatible install... /usr/bin/install -c
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking how to run the C preprocessor... gcc -E
checking for a sed that does not truncate output... (cached) /usr/bin/sed
checking for code coverage support... no
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports the include directive... yes (GNU style)
checking dependency style of gcc... gcc3
checking curl version... 7.83.0-DEV
configure: error: select TLS backend(s) or disable TLS with --without-ssl.

Select from these:

  --with-amissl
  --with-bearssl
  --with-gnutls
  --with-mbedtls
  --with-nss
  --with-openssl (also works for BoringSSL and libressl)
  --with-rustls
  --with-schannel
  --with-secure-transport
  --with-wolfssl

报错为:configure: error: select TLS backend(s) or disable TLS with --without-ssl. 根据curl安装时出现:configure: error: select TLS backend(s) or disable TLS with --without-ssl.这篇博客的方法,末尾加上参数 --with-wolfssl即可 ./configure --prefix=/usr/ --with-wolfssl 所以: 首先执行:./configure --prefix=/usr/ --with-wolfssl,如下图所示:

执行make

执行make install安装

2、方式二:直接使用cmake和make工具构建

首先需要下载安装cmake工具,可以去cmake官网下载,目前最新版本是:3.23.0

在libcurl源码目录/root/GithubProjects/curl分别执行如下命令:

代码语言:javascript
复制
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr ..  
make
make install

三、编写libcurl测试程序

可以在libcurl源代码目录的docs/examples/找到一些官方提供的示例程序,如下图所示:

随便找一个示例程序例如http-post.c进行验证: http-post.c

代码语言:javascript
复制
/***************************************************************************
 *                                  _   _ ____  _
 *  Project                     ___| | | |  _ \| |
 *                             / __| | | | |_) | |
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
 * are also available at https://curl.haxx.se/docs/copyright.html.
 *
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
 * copies of the Software, and permit persons to whom the Software is
 * furnished to do so, under the terms of the COPYING file.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ***************************************************************************/
/* <DESC>
 * simple HTTP POST using the easy interface
 * </DESC>
 */
#include <stdio.h>
#include <curl/curl.h>

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

  /* In windows, this will init the winsock stuff */
  curl_global_init(CURL_GLOBAL_ALL);

  /* get a curl handle */
  curl = curl_easy_init();
  if(curl) {
    /* First set the URL that is about to receive our POST. This URL can
       just as well be a https:// URL if that is what should receive the
       data. */
    curl_easy_setopt(curl, CURLOPT_URL, "http://postit.example.com/moo.cgi");
    /* Now specify the POST data */
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=daniel&project=curl");

    /* 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);
  }
  curl_global_cleanup();
  return 0;
}

gcc http-post.c -o http-post -lcurl ./http-post 执行结果如下图所示:

四、参考资料

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-04-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • CentOS8中源码安装libcurl库
  • CentOS8中源码安装libcurl库
    • 一、下载libcurl源代码
      • 二、编译构建libcurl库
        • 1、方式一:使用configure和make构建
        • 2、方式二:直接使用cmake和make工具构建
      • 三、编写libcurl测试程序
        • 四、参考资料
        相关产品与服务
        命令行工具
        腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档