文章目录

  • 下载
  • 安装cmake
  • 编译curl
  • 安装
  • 简单使用

下载

从GitHub下载最新版本的 curl 源码:

git clone https://github.com/curl/curl.git

安装cmake

一句话的事情:

sudo apt-get install cmake

编译curl

  1. 进入curl目录下,创建一个build文件夹,用于存放编译产生的中间文件、动态库、头文件等内容:
cd curlmkdir build
  1. 进入build文件夹
cd build
  1. 通过cmke生成Makefile,注意,cmake的语法是:cmake [路径],.. 表示上一级目录
cmake ..
  1. 在执行完成后你会发现当前目录下存在一个Makefile文件,你直接make就可以编译了。
make

安装

在编译完成后,可以进行安装,注意要用sudo权限:

sudo make install

它按照的位置信息如下:

-- Install configuration: ""
-- Installing: /usr/local/bin/curl-config
-- Installing: /usr/local/lib/pkgconfig/libcurl.pc
-- Installing: /usr/local/include/curl
-- Installing: /usr/local/include/curl/urlapi.h
-- Installing: /usr/local/include/curl/stdcheaders.h
-- Installing: /usr/local/include/curl/curl.h
-- Installing: /usr/local/include/curl/typecheck-gcc.h
-- Installing: /usr/local/include/curl/system.h
-- Installing: /usr/local/include/curl/multi.h
-- Installing: /usr/local/include/curl/easy.h
-- Installing: /usr/local/include/curl/curlver.h
-- Installing: /usr/local/include/curl/mprintf.h
-- Installing: /usr/local/lib/cmake/CURL/CURLTargets.cmake
-- Installing: /usr/local/lib/cmake/CURL/CURLTargets-noconfig.cmake
-- Installing: /usr/local/lib/cmake/CURL/CURLConfigVersion.cmake
-- Installing: /usr/local/lib/cmake/CURL/CURLConfig.cmake
-- Installing: /usr/local/lib/libcurl.so
-- Installing: /usr/local/bin/curl
-- Set runtime path of "/usr/local/bin/curl" to ""

最后更新一下系统的链接库信息,注意也要用sudo权限:

sudo ldconfig -v

简单使用

在curl的example随便找一个例子:

  • https.c
/****************************************************************************                                  _   _ ____  _*  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 HTTPS GET* </DESC>*/
#include <stdio.h>
#include <curl/curl.h>int main(void)
{CURL *curl;CURLcode res;curl_global_init(CURL_GLOBAL_DEFAULT);curl = curl_easy_init();if(curl) {curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");#ifdef SKIP_PEER_VERIFICATION/** If you want to connect to a site who isn't using a certificate that is* signed by one of the certs in the CA bundle you have, you can skip the* verification of the server's certificate. This makes the connection* A LOT LESS SECURE.** If you have a CA cert for the server stored someplace else than in the* default bundle, then the CURLOPT_CAPATH option might come handy for* you.*/curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
#endif#ifdef SKIP_HOSTNAME_VERIFICATION/** If the site you're connecting to uses a different host name that what* they have mentioned in their server certificate's commonName (or* subjectAltName) fields, libcurl will refuse to connect. You can skip* this check, but this will make the connection less secure.*/curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
#endif/* 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;
}

然后随便编写一个Makefile文件,注意需要动态链接curl库 -lcurl

  • Makefile:
CC=gcc
SRC = $(wildcard *.c */*.c)
OBJS = $(patsubst %.c, %.o, $(SRC))
DEP_FILES := $(patsubst %, .%.d,$(OBJS))
DEP_FILES := $(wildcard $(DEP_FILES))
FLAG = -g -Werror -I. -Iinclude -lpthread -lcurl
TARGET = targets$(TARGET):$(OBJS)$(CC) -o $@ $^ $(FLAG)ifneq ($(DEP_FILES),)
include $(DEP_FILES)
endif%.o:%.c$(CC) -o $@ -c $(FLAG) $< -g -MD -MF .$@.dclean:rm -rf $(TARGET) $(OBJS)distclean:rm -rf $(DEP_FILES).PHONY:clean

编译并运行:

013 git:(master) ✗ makegcc -o https.o -c -g -Werror -I. -Iinclude -lpthread -luv -lcurl https.c -g -MD -MF .https.o.d
gcc -o targets https.o -g -Werror -I. -Iinclude -lpthread -luv -lcurl➜  013 git:(master) ✗ ./targets <!doctype html>
<html>
<head><title>Example Domain</title><meta charset="utf-8" /><meta http-equiv="Content-type" content="text/html; charset=utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" /><style type="text/css">body {background-color: #f0f0f2;margin: 0;padding: 0;font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;}div {width: 600px;margin: 5em auto;padding: 2em;background-color: #fdfdff;border-radius: 0.5em;box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);}a:link, a:visited {color: #38488f;text-decoration: none;}@media (max-width: 700px) {div {margin: 0 auto;width: auto;}}</style>
</head><body>
<div><h1>Example Domain</h1><p>This domain is for use in illustrative examples in documents. You may use thisdomain in literature without prior coordination or asking for permission.</p><p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>

curl安装使用【超级无敌简单】相关推荐

  1. vscode中使用git,超级无敌简单

    vscode中使用git,超级无敌简单 一.复制远端地址 https://gitee.com/zhaojia77/react-foot.git 二.打开vscode 1.点击源代码管理--2.点击克隆 ...

  2. Centos7超级无敌简单的PXE安装系统手动与自动化

    手动PXE网络装机 查看防火墙,内核关了没有 一定要关掉虚拟机设置的自带的dhcp服务 mount /dev/cdrom /mnt       #挂载光盘 yum环境最基本的设置 mkdir -p / ...

  3. STM32CubeIDE用DAP调试的超级无敌简单方法——2022.01.07

    STM32CubeIDE作为ST生态中重要的一环,必然以支持自家的ST-LINK为第一要务.不过当我们手上没有ST-LINK只有其他调试器时也是可以debug和下载的,只需要做一丢丢的简单操作,下面这 ...

  4. Mac安装Hadoop(超级无敌宇宙爆炸详细)

    一.设置ssh免密登录 首先打开mac的系统偏好设置->共享->勾选远程登录 1.打开终端terminal,输入命令:ssh-keygen -t rsa,一直回车即可 2.查看生成的公钥和 ...

  5. 最通俗易懂的超级无敌简单的HTML表格添加功能案例

    背景 1.有元素ol.li: 2.需要将内容添加到li元素: 3.点击添加按钮,输入内容,点击确定即可添加. 主要流程 以上流程描述了最简单的添加过程. 简化流程 简化流程帮助更好的理解数据的流向. ...

  6. 超级无敌简单题(鸽子数)

    欢迎访问https://blog.csdn.net/lxt_Lucia-- 宇宙第一小仙女\(^o^)/--萌量爆表求带飞=≡Σ((( つ^o^)つ~ dalao们点个关注呗-- ---------- ...

  7. hadoop +hbase+zookeeper 伪分布安装(超级无敌详细)

    hadoop +hbase+zookeeper 伪分布安装(超级无敌详细) hadoop 配置 图片打不开的可以点击下方链接直接去图床查看,辣鸡CSDN 安装jdk sudo apt update// ...

  8. Java小记-Vue/ElementUI/Axios(超级无敌认真好用,万字收藏篇!!!!)

    文章目录 Vue/ElementUI/Axios 前言 1 Vue简介 2 Vue的安装 3 Vue的简单使用 4 Vue的指令 4.1 什么是Vue的指令 4.2 Vue常用指令 5 Element ...

  9. hyperterminal使用教程_如何在Win7中安装使用超级终端Hyper Terminal(转)

    [整理]如何在Win7中安装使用超级终端Hyper Terminal how install hyper terminal into Win7 作者:crifan 联系方式:green-waste ( ...

  10. 超级无敌数字加密算法

    超级无敌数字加密算法 为了让大家过一个开心的假期,给大家出一个非常简单的签到题吧 这真的是一个非常简单的签到题 相信你一定能够做得出来的吧 输入一个4位数,将其加密后输出.方法是将该数每一位上的数字加 ...

最新文章

  1. 【c语言】蓝桥杯算法训练 1的个数
  2. 深入理解JavaScript系列(32):设计模式之观察者模式
  3. es6的Map()构造函数
  4. 使用python高通滤波器时报错numpy.linalg.linalg.LinAlgError: Singular matrix
  5. Python入门到精通三天速成第一讲——创建自定义类
  6. 深度学习caffe:最优化方法
  7. 联想小新13pro安装ubuntu双系统心得(解决无法识别启动U盘等问题)
  8. 深度分析:多元化布局或成香飘飘营销转型的重要一环
  9. 《游戏引擎架构》试读感想
  10. winRE环境下使用xcopy时显示未找到文件
  11. GPRS模块 测试项目
  12. 中琅条码软件连续打印设置方法
  13. ERNIE: Enhanced Language Representation with Informative Entities 论文研读
  14. vue实现静音播放video标签(视频/视频流)
  15. SpringBoot 实现 Office 各种格式在线预览(详细教程,包教包会)
  16. UVA11992(线段树)
  17. HFSS学习笔记—2.HFSS工作界面
  18. ps做出一个框,然后拉图片进去只显示框中得部分
  19. 不下载英语包 Vista照样可以玩梦幻桌面
  20. sql server和mysql 分页_基于Sql server数据库的四种分页方式总结

热门文章

  1. 【网络技术题库整理5】网络安全技术
  2. springboot微信小程序 获取微信unionid
  3. java wsdl文件生成代码_wsdl文件生成java代码
  4. MQTT5协议报文格式
  5. 2020深圳杯数学建模C题
  6. 软件开发 | 如何写软件开发文档
  7. 计算机无法安装小丸工具箱,小丸工具箱电脑版
  8. php时间格式转换成时间戳,php怎么把时间格式转换为时间戳?
  9. java 异步写_Java异步编程实战
  10. FileResponse django下载文件问题