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函数调用。

#include "curl_setup.h"

#ifdef USE_WIN32_IDN

#include "curl_multibyte.h"
#include "curl_memory.h"
#include "warnless.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

bool curl_win32_idn_to_ascii(const char *in, char **out);
bool curl_win32_ascii_to_idn(const char *in, char **out);

bool curl_win32_idn_to_ascii(const char *in, char **out)
{
  bool success = FALSE;

  wchar_t *in_w = Curl_convert_UTF8_to_wchar(in);
 
  if(in_w) {
    wchar_t punycode[IDN_MAX_LENGTH];
    int chars = -1;
    fnIdnToAscii IdnToAscii;
    HINSTANCE hNormalizDLL = LoadLibrary("normaliz.dll");
    if (!hNormalizDLL) {
        FreeLibrary(hNormalizDLL);
        assert(hNormalizDLL);
        return FALSE;
    }
    IdnToAscii = (fnIdnToAscii)GetProcAddress(hNormalizDLL, "IdnToAscii");
    if (!IdnToAscii) {
        assert(IdnToAscii);
        return TRUE;
    }
    chars = IdnToAscii(0, in_w, -1, punycode, IDN_MAX_LENGTH);
    
    free(IdnToAscii);
    FreeLibrary(hNormalizDLL);

    free(in_w);
    if(chars) {
      *out = Curl_convert_wchar_to_UTF8(punycode);
      if(*out)
        success = TRUE;
    }
  }

  return success;
}

bool curl_win32_ascii_to_idn(const char *in, char **out)
{
  bool success = FALSE;

  wchar_t *in_w = Curl_convert_UTF8_to_wchar(in);
  if(in_w) {
    size_t in_len = wcslen(in_w) + 1;
    wchar_t unicode[IDN_MAX_LENGTH];
    int chars = -1;
    fnIdnToUnicode IdnToUnicode;
    
    HINSTANCE hNormalizDLL = LoadLibrary("normaliz.dll");
    if (!hNormalizDLL) {
        FreeLibrary(hNormalizDLL);
        assert(hNormalizDLL);
        return FALSE;
    }
    IdnToUnicode = (fnIdnToUnicode)GetProcAddress(hNormalizDLL, "IdnToUnicode");
    if (!IdnToUnicode) {
        assert(IdnToUnicode);
        return FALSE;
    }
    chars = IdnToUnicode(0, in_w, curlx_uztosi(in_len),
                             unicode, IDN_MAX_LENGTH);
    
    free(IdnToUnicode);
    FreeLibrary(hNormalizDLL);
    free(in_w);
    if(chars) {
      *out = Curl_convert_wchar_to_UTF8(unicode);
      if(*out)
        success = TRUE;
    }
  }

  return success;
}

#endif /* USE_WIN32_IDN */


你可能感兴趣的:(c++)