這幾天須要使用openssl,前期本機上保存的目錄不知道哪天整理的時候刪除了,索性下載最新的本身編譯一下;ui
在最新版的openssl(openssl-1.0.2e),編譯過程當中出現了不少問題,這裏主要彙總一下:spa
使用環境:win10/VC2015debug
一、如何編譯unicode 版openssl?code
在配置時添加選項:orm
perl Configure VC-WIN32 -DUNICODE -D_UNICODEblog
二、如何使得編譯的openssl庫在debug程序時不報錯?ssl
修改ms\do_xx.bat文件便可,以下所示,加上deubg就會生成*.dbg輸出目錄,不然生成release版本ci
perl util\mk1mf.pl debug no-asm VC-WIN32 >ms\nt.makunicode
三、如何生成靜態庫?openssl
nmake -f ms\ntdll.mak
nmake -f ms\nt.mak
後一項編譯生成靜態庫
四、編譯庫可能存在如下問題:
1>libeay32.lib(cryptlib.obj) : error LNK2001: 沒法解析的外部符號 __vsnwprintf
1>libeay32.lib(cryptlib.obj) : error LNK2001: 沒法解析的外部符號 __vsnprintf
1>libeay32.lib(cryptlib.obj) : error LNK2001: 沒法解析的外部符號 ___iob_func
1>libeay32.lib(pem_lib.obj) : error LNK2001: 沒法解析的外部符號 ___iob_func
1>libeay32.lib(ui_openssl.obj) : error LNK2001: 沒法解析的外部符號 ___iob_func
1>libeay32.lib(v3_utl.obj) : error LNK2001: 沒法解析的外部符號 _sscanf
1>libeay32.lib(dso_win32.obj) : error LNK2001: 沒法解析的外部符號 _sprintf
如下是解決方法:
對於1.2個問題是因爲_vsntprintf在系統庫中已經有定義了,因此先注掉cryptlib.c中的定義,而後再把_vsntprintf 使用的地方用UNICODE宏區分開,見以下所示:
1 /* 2 # if defined(_UNICODE) || defined(__UNICODE__) 3 # define _vsntprintf _vsnwprintf 4 # else 5 # define _vsntprintf _vsnprintf 6 # endif 7 */ 8 9 ...... 10 11 #if defined(_UNICODE) || defined(__UNICODE__) 12 _vsnwprintf(buf, sizeof(buf) / sizeof(TCHAR) - 1, fmt, ap); 13 #else 14 _vsnprintf(buf, sizeof(buf) / sizeof(TCHAR) - 1, fmt, ap); 15 #endif //#if defined(_UNICODE) || defined(__UNICODE__)
對於3.4.5三個問題(___iob_func)是因爲VC++2015對此宏的定義不同致使的,須要修改的地方是e_os.h文件
1 # if defined(_MSC_VER) && !defined(_WIN32_WCE) && !defined(_DLL) && defined(stdin) 2 # if _MSC_VER>=1300 && _MSC_VER<1600 3 4 # undef stdin 5 # undef stdout 6 # undef stderr 7 FILE *__iob_func(); 8 # define stdin (&__iob_func()[0]) 9 # define stdout (&__iob_func()[1]) 10 # define stderr (&__iob_func()[2]) 11 # elif _MSC_VER>1800 /*VC2015*/ 12 FILE *__acrt_iob_func(unsigned) 13 # define stdin (__acrt_iob_func(0)) 14 # define stdout (__acrt_iob_func(1)) 15 # define stderr (__acrt_iob_func(2)) 16 # elif _MSC_VER<1300 && defined(I_CAN_LIVE_WITH_LNK4049) 17 # undef stdin 18 # undef stdout 19 # undef stderr 20 /* 21 * pre-1300 has __p__iob(), but it's available only in msvcrt.lib, 22 * or in other words with /MD. Declaring implicit import, i.e. with 23 * _imp_ prefix, works correctly with all compiler options, but 24 * without /MD results in LINK warning LNK4049: 'locally defined 25 * symbol "__iob" imported'. 26 */
第6個問題,修改v3_utl.c
1 #if defined(_UNICODE) || defined(__UNICODE__) 2 if (wscanf(in, "%d.%d.%d.%d", &a0, &a1, &a2, &a3) != 4) 3 #else 4 if (sscanf(in, "%d.%d.%d.%d", &a0, &a1, &a2, &a3) != 4) 5 #endif //
第7個問題,修改dso_win32.c
1 #if defined(_UNICODE) || defined(__UNICODE__) 2 if (transform) 3 wprintf(translated, "%s.dll", filename); 4 else 5 wprintf(translated, "%s", filename); 6 #else 7 if (transform) 8 sprintf(translated, "%s.dll", filename); 9 else 10 sprintf(translated, "%s", filename); 11 #endif //#if defined(_UNICODE) || defined(__UNICODE__)
五、編譯過程當中的其它問題均可以在網上直接找到,如nasm的問題等。