Using the OpenSSL management certificate and SSL programming part 3rd: Export MinGW compiled OpenSSL DLLs to Def and Lib for msvc use

Source: Internet
Author: User
Tags erro

Export the MinGW compiled OpenSSL DLL to Def and Lib for msvc use

Before we used MinGW to compile OpenSSL into a dynamic library, we got the following 2 DLL files:

Libeay32.dll

Ssleay32.dll

Then use the following script to generate the module definition files (. def,. Lib and. Exp) required by Windows MSVC,

Then you can use it in the VC. Prerequisite system to install vs.


System Requirements:

Windows7+vs Studio (later) +msys

1) generate the Python code for the module definition file according to the 32-bit DLL:

#!/usr/bin/python# filename:mklib32.py#--Make 32bits Windows module files from MinGW x86. dll# Author: [EMAIL PR otected]# date:2015-12-31# Note:run in msys####################################################################### Import OS, sys, platformimport optparse, configparserappfile = Os.path.realpath (sys.argv[0]) appname,_ = Os.path.splitext (Os.path.basename (appfile)) AppVer = "1.0" APPHELP = "make 32bits Windows module files from MinGW. dll" # # # # # # # # # #################################### Check if file existsdef file_exists (file): If File and Os.path.isfile (file) and OS . Access (file, OS. R_OK): Return True else:return false######################################## Check system is Msys or cmd Def check_system (): # Platform.uname (): print "* Platform:", Platform.platform () print "* Version:", PLATFORM.V Ersion () print "* Architecture:", Platform.architecture () print "* Machine:", Platform.machine () print "* NETW Ork node: ", Platform.node () pRint "* Processor:", platform.processor () if platform.architecture ()! = (' 32bit ', ' WindowsPE '): Sys.exit ("[Erro R] Platform not support. ")  ######################################## get MSVC path Environmentdef Search_vspath (): For MSVC in [150, 140, 130, 120,            "Vsenv" = "vs%dcomntools"% msvc Vspath = os.getenv (vsenv) if Vspath: Print "*%s= '%s '"% (vsenv, Vspath) return Vspath sys.exit ("[ERROR] Vs_comntools not found") ##### ################################### Check DLL FileDef Validate_args (Dll_file, Out_path): if Out_path:if not OS. Path.exists (Out_path): Sys.exit ("[ERROR] Specified out path NOT exists:%s"% Out_path) if not os.path.i Sdir (Out_path): Sys.exit ("[ERROR] Specified out path not dir:%s"% out_path) Else:out_path = Os.pat H.dirname (appfile) dllbases = [] titles = [] if file_exists (dll_file): DllPath = Os.path.dirname (dll_file) dllbase = Os.path.basename (dll_file) title, ext = Os.path.splitext (dllbase) if Ext.lower ()! = ". DL    L ": Sys.exit (" [ERROR] not a. dll file:%r "% dll_file) return (DllPath, [Dllbase], [title], Out_path)            Elif Os.path.isdir (Dll_file): For F in Os.listdir (dll_file): PF = Os.path.join (Dll_file, F)                If File_exists (PF): Dllbase = Os.path.basename (PF) title, ext = Os.path.splitext (dllbase)         If ext.lower () = = ". dll": Dllbases.append (dllbase) titles.append (title)             If not Len (dllbases): Sys.exit ("[ERROR] DLL files not found in given path:%s"% dll_file) Else: Return (Dll_file, dllbases, titles, Out_path) else:sys.exit ("[ERROR] either file is missing or is n OT readable ") ###################################### #def check_results (Out_path, title): Out_files = [] def_file = OS . Path.join (Out_path, TitLe + ". def") if not file_exists (def_file): print "[ERROR] ' File NOT exists:%s"% Def_file Else:out_fi Les.append (def_file) lib_file = Os.path.join (Out_path, title + ". Lib") if not file_exists (lib_file): print "[ ERROR] File NOT exists:%s "% lib_file else:out_files.append (lib_file) exp_file = Os.path.join (Out_path, Tit Le + ". Exp") if not file_exists (exp_file): print "[ERROR] ' File NOT exists:%s"% Exp_file Else:out_fi Les.append (exp_file) return out_files############################################################ Usage for MSYS:# p    Ython mklib32.py-i "C:\DEVPACK\MinGW\msys\1.0\local\win32\bin"-o "./win32" #if __name__ = = "__main__": Print "*" * 54 Print "*%-50s *"% (APPNAME + "version:" + appver) print "*%-50s *"% APPHELP print "*" * If Len (sys.ar        GV) = = 1:sys.exit ("[ERROR] Input DLL file not specified.") Parser = Optparse. Optionparser (usage= ' Python%prog [options] ', version= "%Prog "+ AppVer" parser.add_option ("-V", "--verbose", action= "Store_true", dest= "verbose", Default=true,    help= "Be verbose (the default).")    Parser.add_option ("-Q", "--quiet", action= "Store_false", dest= "verbose", help= "quiet (no Output).") Group = Optparse. OptionGroup (parser, APPNAME, APPHELP) parser.add_option_group (group) group.add_option ("-I", "--dll-file", act Ion= "Store", dest= "Dll_file", Default=none, help= "specify input. dll file or path to export") group.add_option (" -O ","--out-path ", action=" store ", dest=" Out_path ", Default=none, help=" Specify path for Output files ") (  OPTs, args) = Parser.parse_args () check_system () Vspath = Search_vspath () (DllPath, dllbases, titles, out_path) =         Validate_args (Opts.dll_file, Os.path.realpath (opts.out_path)) print "* Input files:", DllPath for DLLs in Dllbases: Print "*:", dll print "* Output path:", Out_path out_dict ={} for I in range (0, Len (dllbases)): print "-" *50 dllbase = dllbases[i] title = Titles[i] D  Ll_file = Os.path.join (DllPath, dllbase) print "* Make Windows Module definition:%s.def"% title Msyscmd = ' Pexports '%s '-o > '%s.def '% (Dll_file, Os.path.join (Out_path, title)) ret = Os.system (msyscmd) if re T! = 0:sys.exit ("[ERROR] MSYS command:%s"% msyscmd) print "* Make Windows Module import file:%s.lib '% title Libcmd = ' CD '%s ' &vsvars32.bat&cd '%s ' &lib/def:%s.def/machine:i386/out:%s.lib '% (Vspath,  Out_path, title, title) ret = Os.system (libcmd) if ret! = 0:sys.exit ("[ERROR] lib command:%s"% Libcmd) Out_dict[title] = Check_results (Out_path, title) print "=============== Output Files report =======            ======== "for title, files in Out_dict.items (): print"%s.DLL = "% title for F in Files: Print "*", OS.PAth.basename (f) 

2) generate the Python code for the module definition file according to the 64-bit DLL:

#!/usr/bin/python# filename:mklib64.py#--Make 64bits Windows module files from MinGW x64. dll# Author: [EMAIL PR otected]# date:2015-12-31# Note:run in msys####################################################################### Import OS, sys, platformimport optparse, configparserappfile = Os.path.realpath (sys.argv[0]) appname,_ = Os.path.splitext (Os.path.basename (appfile)) AppVer = "1.0" APPHELP = "make 64bits Windows module files from MinGW. dll" # # # # # # # # # #################################### Check if file existsdef file_exists (file): If File and Os.path.isfile (file) and OS . Access (file, OS. R_OK): Return True else:return false######################################## Check system is Msys or cmd Def check_system (): # Platform.uname (): print "* Platform:", Platform.platform () print "* Version:", PLATFORM.V Ersion () print "* Architecture:", Platform.architecture () print "* Machine:", Platform.machine () print "* NETW Ork node: ", Platform.node () pRint "* Processor:", platform.processor () if platform.architecture ()! = (' 32bit ', ' WindowsPE '): Sys.exit ("[Erro R] Platform not support. ") ######################################## get MSVC path environment# C:\Program Files (x86) \microsoft Visual Studio 12.0\ Vcdef Search_vspath (): For msvc in [Max., $, +,--------------]--vsenv = "Vs%dcomntools"% msv c Vspath = os.getenv (vsenv) If Vspath:vcbat = Os.path.join (Os.path.dirname (Os.path.dirname (OS.PA Th.dirname (Vspath))), "Vc\\vcvarsall.bat") if File_exists (vcbat): Vspath = Os.path.dirname (vcbat ) print "*%s= '%s '"% (vsenv, Vspath) return Vspath sys.exit ("[ERROR] Vcvarsall.bat not        Found ") ######################################## Check DLL FileDef Validate_args (Dll_file, Out_path): if Out_path: If not os.path.exists (Out_path): Sys.exit ("[ERROR] Specified out path NOT exists:%s"% Out_path) if nOT Os.path.isdir (Out_path): Sys.exit ("[ERROR] Specified out path not dir:%s"% Out_path) else:out_p Ath = os.path.dirname (appfile) dllbases = [] titles = [] if file_exists (dll_file): DllPath = Os.path.dirna Me (dll_file) dllbase = Os.path.basename (dll_file) title, ext = Os.path.splitext (dllbase) if Ext.lower ()! = ". dll": Sys.exit ("[ERROR] not a. dll file:%r"% dll_file) return (DllPath, [Dllbase], [title], OU            T_path) elif Os.path.isdir (dll_file): For F in Os.listdir (dll_file): PF = Os.path.join (Dll_file, F) If File_exists (PF): Dllbase = Os.path.basename (PF) title, ext = Os.path.splitext (d Llbase) if ext.lower () = = ". dll": Dllbases.append (dllbase) Titles.app        End (title) if not Len (dllbases): Sys.exit ("[ERROR] DLL files not found in given path:%s"% dll_file) Else:reTurn (Dll_file, dllbases, titles, Out_path) else:sys.exit ("[ERROR] either file is missing or was not readable") # ##################################### #def check_results (Out_path, title): Out_files = [] Def_file = Os.path.join (out        _path, Title + ". Def") if not file_exists (def_file): print "[ERROR] File not exists:%s"% Def_file else:        Out_files.append (def_file) lib_file = Os.path.join (Out_path, title + ". Lib") if not file_exists (lib_file): Print "[ERROR] File not exists:%s"% lib_file else:out_files.append (lib_file) Exp_file = Os.path.join (out        _path, title + ". Exp") if not file_exists (exp_file): print "[ERROR] File not exists:%s"% Exp_file else: Out_files.append (exp_file) return out_files############################################################ Usage for M sys:# python mklib64.py-i "C:\DEVPACK\MinGW\msys\1.0\local\win64\bin"-o "./win64" #if __name__ = = "__main__": Print * "*" * print "*%-50s * "% (APPNAME +" version: "+ appver) print" *%-50s * "% APPHELP print" * "* If Len (sys.argv) = = 1:        Sys.exit ("[ERROR] Input DLL file not specified.") Parser = Optparse. Optionparser (usage= ' Python%prog [options] ', version= "%prog" + appver) parser.add_option ("-V", "--verbose", act    Ion= "Store_true", dest= "verbose", Default=true, help= "Being verbose (this is the default).")    Parser.add_option ("-Q", "--quiet", action= "Store_false", dest= "verbose", help= "quiet (no Output).") Group = Optparse. OptionGroup (parser, APPNAME, APPHELP) parser.add_option_group (group) group.add_option ("-I", "--dll-file", act Ion= "Store", dest= "Dll_file", Default=none, help= "specify input. dll file or path to export") group.add_option (" -O ","--out-path ", action=" store ", dest=" Out_path ", Default=none, help=" Specify path for Output files ") ( OPTs, args) = Parser.parse_args () check_system () Vspath = Search_vspath ()    (DllPath, dllbases, titles, out_path) = Validate_args (Opts.dll_file, Os.path.realpath (opts.out_path)) print "* INP UT files: ", DllPath for DLLs in Dllbases:print" *: ", dll print" * Output path: ", Out_path O Ut_dict = {} for I in range (0, Len (dllbases)): print "-" *50 dllbase = dllbases[i] title = Titles[i        ] Dll_file = Os.path.join (DllPath, dllbase) print "* Make Windows Module definition:%s.def"% title        Msyscmd = ' pexports '%s '-o > '%s.def '% (Dll_file, Os.path.join (Out_path, title)) ret = Os.system (msyscmd) IF ret! = 0:sys.exit ("[ERROR] MSYS command:%s"% msyscmd) print "* Make Windows Module import fi Le:%s.lib "% title Libcmd = ' cd"%s "&vcvarsall.bat x86_amd64&cd"%s "&lib/def:%s.def/machine:amd64/o Ut:%s.lib '% (Vspath, Out_path, title, title) ret = Os.system (libcmd) if ret! = 0:sys.exit ("[ERR OR] lib command:%s "% lIbcmd) Out_dict[title] = Check_results (Out_path, title) print "=============== Output Files report =============            = = "For title, files in Out_dict.items (): print"%s.DLL = "% title for F in Files: Print "*", Os.path.basename (f)

Very simple to use, open the Msys command line:


$ python mklib64.py-i "C:\DEVPACK\MinGW\msys\1.0\local\win64\bin"-o "./win64"

MKLIB64 version:1.0 * * Make 64bits Windows module files from MinGW. dll ******************************************************* * platform:windows-7-6.1. 7601-SP1 * version:6.1.7601 * Architecture: (' 32bit ', ' WindowsPE ') * MACHINE:AMD64 * Network node:thinkpad-w520 * PROCE Ssor:intel64 Family 6 Model Stepping 7, Genuineintel * vs120comntools= ' C:\Program Files (x86) \microsoft Visual Studio 12.0\VC ' * Input files:c:\devpack\mingw\msys\1.0\local\win64\bin *: Libeay32.dll *: SSLEAY32.DL L * Output path:c:\devpack\workspace\temp\win64--------------------------------------------------* Make Windows Module Definition:libeay32.def * Make Windows Module import file:libeay32.libMicrosoft (R) Library Manager Version 12.00  .21005.1Copyright (C) Microsoft Corporation.   All rights reserved. Creating library Libeay32.lib and Object Libeay32.exp--------------------------------------------------* Make Windows Module DEFINITION:SSLEAY32.DEF * Make Windows Module import file:ssleay32.libMicrosoft (R) Library Manage  R Version 12.00.21005.1Copyright (C) Microsoft Corporation.   All rights reserved.   Creating library Ssleay32.lib and Objects ssleay32.exp=============== Output Files Report ===============ssleay32.dll = * Ssleay32.def * Ssleay32.lib * Ssleay32.explibeay32.dll = * Libeay32.def * libeay32.lib * libeay32.exp

The 64bits filename is still??? 32.


Using the OpenSSL management certificate and SSL programming part 3rd: Export MinGW compiled OpenSSL DLLs to Def and Lib for msvc use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.