在windows下,编译可访问https的libcurl静态库过程

1. 首先编译openssl静态库

整个过程用的是 vs2015命令提示工具

需要安装perl
下载地址:添加链接描述
解压后, 在 openssl-1.0.2e目录下创建develop这个文件夹, cd到 openssl-1.0.2e目录下,

a.配置编译文件和模式
执行

perl Configure VC-WIN32 no-asm --prefix=E:\curl\openssl-1.0.2e\develop

VC-WIN32标识windows 32位操作系统,
64位用VC-WIN64A表示, 若要使用debug版本,请使用debug-VC-WIN64A或debug-VC-WIN32
no-asm 表示不用汇编
–prefix=E:\curl\openssl-1.0.2e\develop 是设置安装目录
b.生成编译配置文件
若为Windows 64位系统,执行

ms\do_win64a.bat

若为Windows 32位系统,执行

ms\do_ms.bat

执行这一步之后,在ms目录下会生成nt.mak和ntdll.mak两个编译配置文件
nt.mak 用于生成静态lib库
ntdll.mak 用于生成动态dll库
c.编译
静态库

nmake -f ms\nt.mak	

动态库

nmake -f ms\ntdll.mak

d.测试
测试静态库:

 nmake -f ms\nt.mak test

测试动态库:

 nmake -f ms\ntdll.mak test

若最终显示 passed all tests 则说明生成的库正确
e.安装
安装静态库:

nmake -f ms\nt.mak install

安装动态库:

nmake -f ms\ntdll.mak install

编译安装完成后,会在E:\curl\openssl-1.0.2e\develop目录下看到生成的相关文件夹
f.清楚上次编译
清除上次静态库的编译,以便重新编译:

nmake -f ms\nt.mak clean

清除上次动态库的编译,以便重新编译:

nmake -f ms\ntdll.mak clean

参考:https://blog.csdn.net/mayue_web/article/details/83997969,非常详细

2.编译zlib

a.下载源码
http://zlib.net/zlib-1.2.11.tar.gz
解压后,在zlib根目录下 命令行执行
nmake -f win32/Makefile.msc

3.编译libcurl

a.下载源码
http://curl.haxx.se/download/curl-7.46.0.tar.bz2
b.拷贝所需的openssl与zlib相关库与头文件
.根据curl源代码根目录下winbuild目录下BUILD.WINDOWS.txt的提示
在源代码同级的目录下建立deps文件夹
此时的目录结构如下图(伪目录

somedirectory\
|__curl-src
|    |_winbuild
|
|__deps|_ lib|_ include|_ bin

我这里的deps文件夹目录是 E:\curl\deps
将编译openssl时候,安装目录E:\curl\openssl-1.0.2e\develop\include下的
openssl夹拷贝到E:\curl\deps\include\目录下;
将zlib源码根目录下的zconf.h、zlib.h和zutil.h拷贝到E:\curl\deps\include目录下。
将E:\curl\openssl-1.0.2e\develop\lib目录下的libeay32.lib和ssleay.lib拷贝到E:\curl\deps\lib目录下;
将zlib源码根目录下的zlib.lib拷贝到E:\curl\deps\lib目录下。
c.编译libcurl
命令行进入源代码根目录下 winbuild 目录

nmake RTLIBCFG=static /f Makefile.vc mode=static VC=14 WITH_DEVEL=E:\curl\deps WITH_SSL=static ENABLE_SSPI=no ENABLE_IPV6=no DEBUG=no

参数详细含义如下:

nmake /f Makefile.vc mode=<static or dll> <options>where <options> is one or many of:VC=<6,7,8,9,10,11,12,14>     - VC versionsWITH_DEVEL=<path>            - Paths for the development files (SSL, zlib, etc.)Defaults to sibbling directory deps: ../depsLibraries can be fetched at http://windows.php.net/downloads/php-sdk/deps/Uncompress them into the deps folder.WITH_SSL=<dll or static>     - Enable OpenSSL support, DLL or staticWITH_CARES=<dll or static>   - Enable c-ares support, DLL or staticWITH_ZLIB=<dll or static>    - Enable zlib support, DLL or staticWITH_SSH2=<dll or static>    - Enable libSSH2 support, DLL or staticENABLE_SSPI=<yes or no>      - Enable SSPI support, defaults to yesENABLE_IPV6=<yes or no>      - Enable IPv6, defaults to yesENABLE_IDN=<yes or no>       - Enable use of Windows IDN APIs, defaults to yesRequires Windows Vista or later, or installation from:http://www.microsoft.com/downloads/details.aspx?FamilyID=AD6158D7-DDBA-416A-9109-07607425A815ENABLE_WINSSL=<yes or no>    - Enable native Windows SSL support, defaults to yesGEN_PDB=<yes or no>          - Generate Program Database (debug symbols for release build)DEBUG=<yes or no>            - Debug buildsMACHINE=<x86 or x64>         - Target architecture (default is x86)Static linking of Microsoft's C RunTime (CRT):
==============================================
If you are using mode=static nmake will create and link to the static build of
libcurl but *not* the static CRT. If you must you can force nmake to link in
the static CRT by passing RTLIBCFG=static. Typically you shouldn't use that
option, and nmake will default to the DLL CRT. RTLIBCFG is rarely used and
therefore rarely tested. When passing RTLIBCFG for a configuration that was
already built but not with that option, or if the option was specified
differently, you must destroy the build directory containing the configuration
so that nmake can build it from scratch.Legacy Windows and SSL
======================
When you build curl using the build files in this directory the default SSL
backend will be WinSSL (Windows SSPI, more specifically Schannel), the native
SSL library that comes with the Windows OS. WinSSL in Windows <= XP is not able
to connect to servers that no longer support the legacy handshakes and
algorithms used by those versions. If you will be using curl in one of those
earlier versions of Windows you should choose another SSL backend like OpenSSL.

3.验证

vs2015
添加好包含目录 ,附加库目录, 附加依赖项后,预处理器添加上BUILDING_LIBCURL

// staticLibcurlTest.cpp : 定义控制台应用程序的入口点。
//#include "stdafx.h"
#include <iostream>
#include <curl.h>using namespace std;/**
* 一旦curl接收到数据,就会调用此回调函数
* buffer:数据缓冲区指针
* size:调试阶段总是发现为1
* nmemb:(memory block)代表此次接受的内存块的长度
* userp:用户自定义的一个参数
*/
size_t write_data(void* buffer, size_t size, size_t nmemb, void* userp)
{static int current_index = 0;cout << "current:" << current_index++;cout << (char*)buffer;cout << "---------------" << endl;int temp = *(int*)userp;    // 这里获取用户自定义参数return nmemb;
}int main()
{curl_global_init(CURL_GLOBAL_ALL); // 首先全局初始化CURLCURL* curl = curl_easy_init(); // 初始化CURL句柄if (NULL == curl){return 0;}int my_param = 1;    // 自定义一个用户参数// 设置目标URLcurl_easy_setopt(curl, CURLOPT_URL, "https://api.vxxx/gettime");// 设置接收到HTTP服务器的数据时调用的回调函数curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);// 设置自定义参数(回调函数的第四个参数)curl_easy_setopt(curl, CURLOPT_WRITEDATA, &my_param);// 执行一次URL请求CURLcode res = curl_easy_perform(curl);// 清理干净curl_easy_cleanup(curl);getchar();return 0;
}

参考:
https://blog.csdn.net/fm0517/article/details/91822880
https://blog.csdn.net/huangyimo/article/details/80337496

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/382421.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Go语言爬虫项目将结果写入MySql数据库

来源于Google资深工程师深度讲解Go语言 package mainimport ("fmt""io/ioutil""net/http" )const url "http://www.zhenai.com/zhenghun"func main() {//发送get请求resp, err : http.Get(url)if err ! nil {panic(err)}//关闭通道d…

go语言学习路径

个人记录 go语言如何连接数据库&#xff1a;增删改查 Go语言爬虫项目将结果写入MySql数据库 go语言急速入门

在windows上使用go编译dll文件,供C++调用

C项目是win32的&#xff0c;所以go的编译环境也要改成win32的 cmd下&#xff0c;修改环境变量&#xff1a; set GOARCH386 set CGO_ENABLED1 使用go env 查看是否生效参考&#xff1a;https://bbs.csdn.net/topics/394513992. 2. 安装编译环境 MinGW下载安装gcc,g编译器 参考&…

go语言急速入门

Go 语言极速入门1 - 环境搭建与最简姿势 Go 语言极速入门2 - 基础语法 Go 语言极速入门3 - 内建容器 Go 语言极速入门4 - 面向对象 Go 语言极速入门5 - 面向接口 Go 语言极速入门6 - 闭包 Go 语言极速入门7 - 资源管理与错误处理 Go 语言极速入门8 - Goroutine Go 语言极速入门…

windows远程桌面mstsc使用 代理

转自 https://blog.csdn.net/bodybo/article/details/6638005

go语言扫描四位数可用域名

域名注册查询接口(API)的说明 原文出处 域名查询 接口采用HTTP&#xff0c;POST&#xff0c;GET协议&#xff1a; 调用URL&#xff1a;http://panda.www.net.cn/cgi-bin/check.cgi 参数名称&#xff1a;area_domain 值为标准域名&#xff0c;例&#xff1a;hichina.com 调用…

cmake构建工具 初步01

记录下cmake学习过程&#xff0c;以后还会补充 单目录单文件 demo1 目录下只有一个a1.cpp, 如下图 [rootlocalhost demo1]# tree . ├── a1.cpp └── CMakeLists.txt编写CMakeLists.txt 1 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)2 3 PROJECT(demo1)4 5 ADD_EXECUTABLE(d…

Mysql5.7后的password加密和md5

5.7之后 password函数旧版16位&#xff0c;新版41位&#xff0c;可用select password(‘123456’)查看。md5加密算法&#xff0c;只有16位和32位两种 authentication_string 且5.7之后移除了password&#xff0c;它采用了新的算法 5.7之前 mysql> select user,host,pas…

用python写的简单的http文件服务器demo

import socket import os import re import time from multiprocessing import Processclass CHttpServer(object):"""Httpserver服务端类"""def __init__(self):self.m_serverSocket socket.socket(socket.AF_INET,socket.SOCK_STREAM)self.m_…

从《四驱兄弟》到“联想中国”

《四驱兄弟》 小学的时候看过一个日本的动画片叫四驱兄弟&#xff0c;里面就是一群小朋友代表国家各种比赛&#xff0c;其中让我象比较深刻的是他把美国队描述的非常邪恶&#xff0c;各种破坏别人的车子&#xff0c;通过卑鄙手段取得胜利。然后最后好像是正义战胜邪恶的剧情还…

Mac SecureCRT解决中文乱码

下载地址 https://xclient.info/s/navicat-premium.html#versions SecureCRT解决中文乱码问题 在设置中设置为utf-8之后&#xff0c;还需要 $ sudo vi /etc/profile $打开文件&#xff0c;最后一行添加export LANGzh_CN.UTF-8

音视频之使用sonic.cpp实现音频倍速播放功能

sonic.cpp 是一个音频处理库&#xff0c;可以实现倍速播放。 如果单纯通过修改pcm的采样率来实现音频倍速播放的话&#xff0c;就会出现声音变调的情况。 以下是通过采集windows 虚拟声卡获取到的音频数据&#xff0c; 我的声卡采样率是44100次/秒&#xff0c;audio_buffer_si…

SecurtCRT连接服务器自动断开

mac Terminal-->Anti-idle-->send protocol NO-OP 60勾中

位图原理、代码实现及应用实例

位图的原理&#xff1a; 在位图中采用比特位表示对应的元素存在或者不存在 0&#xff1a;不存在 1&#xff1a;存在例如一个int整数有32个比特位可以表示0-31个整数。 再举一个例子 存入的数字为8988 首先&#xff1a; 8988/32 280 其次&#xff1a; 8988%32 28 再来一个例…

通过修改注册表,实现网页链接中的私有协议启用本地exe进程

私有协议为 coffeeclass://xxxxxx.mp4 注册表如下 Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\coffeeclass] "coffeeClass Protocol" "URL Protocol"""[HKEY_CLASSES_ROOT\coffeeclass\DefaultIcon] "D:\\Program Files (x…

布隆过滤器的原理、应用场景和源码分析实现

原理 布隆过滤器数据结构 布隆过滤器是一个 bit 向量或者说 bit 数组&#xff0c;长这样&#xff1a; 如果我们要映射一个值到布隆过滤器中&#xff0c;我们需要使用多个不同的哈希函数生成多个哈希值&#xff0c;并对每个生成的哈希值指向的 bit 位置 1。 例如针对值 “baid…

判断一个数字是否存在于某一个数据之中

哈希表 这个没啥说的&#xff0c;后面补充 位图 https://blog.csdn.net/csdn_kou/article/details/95337121 布隆过滤器 哈希表位图 https://blog.csdn.net/csdn_kou/article/details/95371085

根据语句自动生成正则表达式

自动生成 http://www.txt2re.com 速查手册 https://www.jb51.net/shouce/jquery/regexp.html

免密登录堡垒机和服务器

免密登录堡垒机 安装oathtool和sshpass 这两个文件安装比较耗费时间&#xff01; brew install oath-toolkit brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb免密登录堡垒机 书写shell脚本 #!/usr/bin/env bash …