Windows下编译OpenSSL最新版(openssl-1.0.2a)

来源:互联网 发布:证大财富 淘宝达人贷 编辑:程序博客网 时间:2024/05/29 19:25


如何在Windows下编译OpenSSL (VS2010使用VC10的cl编译器)
1、安装ActivePerl//初始化的时候,需要用到perl解释器
2、使用VS2010下的Visual Studio 2010 Command Prompt进入控制台模式(这个模式会自动设置各种环境变量)
3、解压缩openssl的包,进入openssl的目录
4、perl configure VC-WIN32
尽量在这个目录下执行该命令,否则找不到Configure文件,或者指定完整的Configure文件路径。
5、ms\do_ms.bat
在解压目录下执行ms\do_ms.bat命令
6、nmake -f ms\ntdll.mak

7、nmake -f ms\nt.mak


测试动态库:
    nmake -f ms\ntdll.mak test
    测试静态库:
    nmake -f ms\nt.mak test

    安装动态库:
    nmake -f ms\ntdll.mak install
    安装静态库:
    nmake -f ms\nt.mak install

    清除上次动态库的编译,以便重新编译:
    nmake -f ms\ntdll.mak clean
    清除上次静态库的编译,以便重新编译:
    nmake -f ms\nt.mak clean



上面的方法编译旧的版本是没有问题的,当时在编译最新的版本可能会报错:

 Assembling: tmp32\sha1-586.asm
tmp32\sha1-586.asm(1427) : error A2070: invalid instruction operands
tmp32\sha1-586.asm(1571) : error A2070: invalid instruction operands
NMAKE : fatal error U1077: 'ml' return code '0x1'
Stop.


解决:

把第4步改为 perl Configure VC-WIN32 no-asm 然后继续5,6,7步

然后又会报下面类似的连接错误:

提示错误:cryptlib.obj : error LNK2001: unresolved external symbol _OPENSSL_ia32_cpuid

out32dll/libeay32.dll : fatal error LNK1120: 1 unresolved externals

修改ms/do_ms.bat 为:

perl util/mkfiles.pl >MINFO
perl util/mk1mf.pl debug no-asm VC-WIN32 >ms/nt.mak
perl util/mk1mf.pl debug dll no-asm VC-WIN32 >ms/ntdll.mak
perl util/mk1mf.pl debug no-asm VC-CE >ms/ce.mak
perl util/mk1mf.pl debug dll no-asm VC-CE >ms/cedll.mak
perl util/mkdef.pl 32 libeay > ms/libeay32.def
perl util/mkdef.pl 32 ssleay > ms/ssleay32.def




编译后
在openssl解压目录下执行,完成编译后。输出的文件在out32dll (6), out32 (7)里面,包括应用程序的可执行文件、lib文件和dll文件

注意:在运行第五步时,cl编译器会抱怨说.\crypto\des\enc_read.c文件的read是The POSIX name for this item is deprecated(不被推荐的),建议使用_read。呵呵,我可不想将OpenSSL中的所有的read函数修改为_read。再看cl的错误代码error C2220,于是上MSDN上查找:
warning treated as error - no object file generated
/WX tells the compiler to treat all warnings as errors. Since an error occurred, no object or executable file was generated.
是由于设置了/WX选项,将所有的警告都作为错误对待,所以。。。

于是打开OpenSSL目录下的MS目录下的ntdll.mak文件,将CFLAG的/WX选项去掉,存盘。。。
继续执行nmake -f ms\ntdll.mak

1 0
原创粉丝点击