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技术快餐
更多资料等你来拿!