将MinGW编译的openssl dll导出def和lib供MSVC使用
前面我们用mingw把openssl 编译成了动态库,得到下面2个dll文件:
libeay32.dll
ssleay32.dll
然后用下面的脚本生成Windows MSVC需要的模块定义文件(.def, .lib和.exp),
然后就可以在VC中使用了. 前提系统要安装VS.
系统要求:
Windows7+VS Studio (2008 and later)+MSYS
1) 根据32位dll生成模块定义文件的python代码:
#!/usr/bin/python
# filename: mklib32.py
# -- Make 32bits windows module files from MinGW x86 .dll
# author: cheungmine@qq.com
# date: 2015-12-31
# note: run in MSYS
#######################################################################
import os, sys, platform
import optparse, ConfigParser
APPFILE = 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 exists
def 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.version()
print " * architecture:", platform.architecture()
print " * machine:", platform.machine()
print " * network node:", platform.node()
print " * processor:", platform.processor()
if platform.architecture() != ('32bit', 'WindowsPE'):
sys.exit("[ERROR] Platform not support.")
#######################################
# get MSVC path environment
def search_vspath():
for msvc in [150, 140, 130, 120, 110, 100, 90, 80, 70, 60]:
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 file
def 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_path = os.path.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() != ".dll":
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)
ti