windows下编译支持https的curl静态库

1、看了很多编译libcurl的文章,很多都已经过时,版本不对,导致根据网络文章无法编译问题;

2、综合多个网络资料最终基本上编译通过的文章如:https://www.cnblogs.com/zzugyl/p/5037152.html

3、但是遇到的问题如下:

(1)自己目录没有说清楚目录关系

编译路径修改为:

perl Configure VC-WIN32 no-asm --prefix=e:/libcurl/deps
将curl-7.46.0、openssl-1.0.2e、zlib-1.2.8放同一个目录,并在改目录建立deps目录,最后编译curl的时候需要的头全部编译或放置到deps目录

(2)编译选项:静态库或动态库

perl Configure VC-WIN32 no-asm --prefix=e:/libcurl/deps
ms\do_ms.bat
nmake -f ms\ntdll.mak  或静态库编译(nmake -f ms\nt.mak)
nmake -f ms\ntdll.mak test
nmake -f ms\ntdll.mak clean
nmake -f ms\ntdll.mak install

 ( 3 ) 编译选项添加:ENABLE_IDN=no

nmake /f Makefile.vc mode=static WITH_SSL=dll WITH_ZLIB=dll DEBUG=no ENABLE_IDN=no

如果静态编译,则编译选项:

E:\libcurl\curl-7.46.0\winbuild>nmake /f Makefile.vc mode=static WITH_SSL=static WITH_ZLIB=dll DEBUG=no ENABLE_IDN=no

 

(4)遇到错误如何解决:

 

     报错 unresolved external symbol __imp__IdnToAscii@20 unresolved external symbol __imp__IdnToUnicode@20

解决方法如下:

修改文件:curl-7.46.0\lib\idn_win32.c

通过动态载入:IdnToUnicode和IdnToAnscii函数调用。

 

修改后如下:

/***************************************************************************
 *                                  _   _ ____  _
 *  Project                     ___| | | |  _ \| |
 *                             / __| | | | |_) | |
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2014, 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 http://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.
 *
 ***************************************************************************/

 /*
  * IDN conversions using Windows kernel32 and normaliz libraries.
  */

#include "curl_setup.h"

#ifdef USE_WIN32_IDN

#include "curl_multibyte.h"

#include "curl_memory.h"
/* The last #include file should be: */
#include "memdebug.h"

#ifdef WANT_IDN_PROTOTYPES
//#  if defined(_SAL_VERSION)
typedef int (*fnIdnToAscii)(DWORD,const WCHAR *,int,WCHAR *,int);
typedef int (*fnIdnToUnicode)(DWORD,const WCHAR *,int,WCHAR *, int);
//#  endif
#endif

#define IDN_MAX_LENGTH 255

int curl_win32_idn_to_ascii(const char *in, char **out);
int curl_win32_ascii_to_idn(const char *in, size_t in_len, char **out_utf8);

int curl_win32_idn_to_ascii(const char *in, char **out)
{
  wchar_t *in_w = Curl_convert_UTF8_to_wchar(in);
  if(in_w) {
    wchar_t punycode[IDN_MAX_LENGTH];

	fnIdnToAscii IdnToAscii;
	HINSTANCE hNormalizDLL = LoadLibrary("normaliz.dll");
	if (!hNormalizDLL) {
		FreeLibrary(hNormalizDLL);
		assert(hNormalizDLL);
		return 0;
	}
	IdnToAscii = (fnIdnToAscii)GetProcAddress(hNormalizDLL, "IdnToAscii");
	if (!IdnToAscii) {
		assert(IdnToAscii);
		return 0;
	}

    if(IdnToAscii(0, in_w, -1, punycode, IDN_MAX_LENGTH) == 0) {
      wprintf(L"ERROR %d converting to Punycode\n", GetLastError());
      free(in_w);
      return 0;
    }
    free(in_w);

    *out = Curl_convert_wchar_to_UTF8(punycode);
    if(!*out)
      return 0;
  }
  return 1;
}

int curl_win32_ascii_to_idn(const char *in, size_t in_len, char **out_utf8)
{
  (void)in_len; /* unused */
  if(in) {
    WCHAR unicode[IDN_MAX_LENGTH];

	fnIdnToUnicode IdnToUnicode;
	HINSTANCE hNormalizDLL = LoadLibrary("normaliz.dll");
	if (!hNormalizDLL) {
		FreeLibrary(hNormalizDLL);
		assert(hNormalizDLL);
		return 0;
	}
	IdnToUnicode = (fnIdnToUnicode)GetProcAddress(hNormalizDLL, "IdnToUnicode");
	if (!IdnToUnicode) {
		assert(IdnToUnicode);
		return 0;
	}

    if(IdnToUnicode(0, (wchar_t *)in, -1, unicode, IDN_MAX_LENGTH) == 0) {
      wprintf(L"ERROR %d converting to Punycode\n", GetLastError());
      return 0;
    }
    else {
      *out_utf8 = Curl_convert_wchar_to_UTF8(unicode);
      if(!*out_utf8)
        return 0;
    }
  }
  return 1;
}

#endif /* USE_WIN32_IDN */
#ifdef WANT_IDN_PROTOTYPES
//#  if defined(_SAL_VERSION)
typedef int (*fnIdnToAscii)(DWORD,const WCHAR *,int,WCHAR *,int);
typedef int (*fnIdnToUnicode)(DWORD,const WCHAR *,int,WCHAR *, int);
//#  endif
#endif

#define IDN_MAX_LENGTH 255

int curl_win32_idn_to_ascii(const char *in, char **out);
int curl_win32_ascii_to_idn(const char *in, size_t in_len, char **out_utf8);

int curl_win32_idn_to_ascii(const char *in, char **out)
{
  wchar_t *in_w = Curl_convert_UTF8_to_wchar(in);
  if(in_w) {
    wchar_t punycode[IDN_MAX_LENGTH];

	fnIdnToAscii IdnToAscii;
	HINSTANCE hNormalizDLL = LoadLibrary("normaliz.dll");
	if (!hNormalizDLL) {
		FreeLibrary(hNormalizDLL);
		assert(hNormalizDLL);
		return 0;
	}
	IdnToAscii = (fnIdnToAscii)GetProcAddress(hNormalizDLL, "IdnToAscii");
	if (!IdnToAscii) {
		assert(IdnToAscii);
		return 0;
	}

    if(IdnToAscii(0, in_w, -1, punycode, IDN_MAX_LENGTH) == 0) {
      wprintf(L"ERROR %d converting to Punycode\n", GetLastError());
      free(in_w);
      return 0;
    }
    free(in_w);

    *out = Curl_convert_wchar_to_UTF8(punycode);
    if(!*out)
      return 0;
  }
  return 1;
}

int curl_win32_ascii_to_idn(const char *in, size_t in_len, char **out_utf8)
{
  (void)in_len; /* unused */
  if(in) {
    WCHAR unicode[IDN_MAX_LENGTH];

	fnIdnToUnicode IdnToUnicode;
	HINSTANCE hNormalizDLL = LoadLibrary("normaliz.dll");
	if (!hNormalizDLL) {
		FreeLibrary(hNormalizDLL);
		assert(hNormalizDLL);
		return 0;
	}
	IdnToUnicode = (fnIdnToUnicode)GetProcAddress(hNormalizDLL, "IdnToUnicode");
	if (!IdnToUnicode) {
		assert(IdnToUnicode);
		return 0;
	}

    if(IdnToUnicode(0, (wchar_t *)in, -1, unicode, IDN_MAX_LENGTH) == 0) {
      wprintf(L"ERROR %d converting to Punycode\n", GetLastError());
      return 0;
    }
    else {
      *out_utf8 = Curl_convert_wchar_to_UTF8(unicode);
      if(!*out_utf8)
        return 0;
    }
  }
  return 1;
}

#endif /* USE_WIN32_IDN */

快来成为我的朋友或合作伙伴,一起交流,一起进步!
QQ群:961179337
微信:lixiang6153
邮箱:lixx2048@163.com
公众号:IT技术快餐
更多资料等你来拿!

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

贝壳里的沙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值