MingW下编译openssl
2013-04-21 23:50
369 查看
因需要在Win 32平台下支持一部分流媒体处理,而且依赖了OpenSSL,所以借助MingW编译了OpenSSL。遇到并解决了几个过程中的问题,使用的openssl版本比较老(项目原因),这些问题也不见得是大家遇到问题的共性,不过写出来跟大家分享下,以免遇到这些问题的朋友再经历这个过程。
编译使用平台MingW,OpenSSL版本:openssl-1.0.0a
1. 编译过程
如果使用./Configure mingw或./config进行配置,在make时会出现如下错误:
导致编译无法继续,感觉是一个配置过程的bug,但是没找到好的办法解决。最终work的编译方法:
编译正常执行。
2. 编译中在engines/e_capi.c出现编译错误
出现错误如下:
e_capi.c: In function 'capi_get_pkey':
e_capi.c:671:3: error: unknown type name 'DSSPUBKEY'
e_capi.c:674:9: error: 'DSSPUBKEY' undeclared (first use in this function)
e_capi.c:674:9: note: each undeclared identifier is reported only once for each function it appears in
e_capi.c:674:20: error: expected expression before ')' token
e_capi.c:675:9: error: request for member 'magic' in something not a structure or union
e_capi.c:678:38: error: request for member 'magic' in something not a structure or union
e_capi.c:683:16: error: request for member 'bitlen' in something not a structure or union
e_capi.c: In function 'capi_rsa_priv_dec':
e_capi.c:912:2: warning: passing argument 6 of 'CryptDecrypt' from incompatible pointer type [enabled by default]
In file included from e_capi.c:72:0:
d:\mingw\bin\../lib/gcc/mingw32/4.7.2/../../../../include/wincrypt.h:1209:23: note: expected 'PDWORD' but argument is of type 'int *'
e_capi.c: In function 'capi_dump_cert':
e_capi.c:1290:2: warning: passing argument 2 of 'd2i_X509' from incompatible pointer type [enabled by default]
In file included from ../include/openssl/engine.h:98:0,
from e_capi.c:106:
../include/openssl/x509.h:833:1: note: expected 'const unsigned char **' but argument is of type 'unsigned char **'
e_capi.c: In function 'capi_open_store':
e_capi.c:1328:25: error: 'CERT_STORE_PROV_SYSTEM_A' undeclared (first use in this function)
e_capi.c: In function 'capi_ctx_new':
e_capi.c:1529:5: error: 'CERT_STORE_READONLY_FLAG' undeclared (first use in this function)
e_capi.c: In function 'capi_load_ssl_client_cert':
e_capi.c:1633:3: warning: passing argument 2 of 'd2i_X509' from incompatible pointer type [enabled by default]
In file included from ../include/openssl/engine.h:98:0,
from e_capi.c:106:
../include/openssl/x509.h:833:1: note: expected 'const unsigned char **' but argument is of type 'const char **'
make[1]: *** [e_capi.o] Error 1
此为MingW平台下wincrypt定义不完整造成,看到网上一位网友的修改方法进行同样处理,问题得以解决,编译$MINGW_HOME/include/wincrypt.h,在1317行之后加入:
3. apps,test链接出现问题
apps下的程序编译出现问题,已经不影响openSSL的使用,但是为了保证编译完整性,还是把问题解决掉,出现问题如下:
很明显是WinSock lib没有在link列表中,于是在编译apps/Makefile,line 29,LIBCRYPTO改为:
LIBCRYPTO=-L.. -lws2_32
相关问题解决,重新make,libcrypto.a链接再次出现问题:
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xb86): undefined reference to `CreateDCA@16'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xb93): undefined reference to `CreateCompatibleDC@4'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xbaa): undefined reference to `GetDeviceCaps@8'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xbc1): undefined reference to `GetDeviceCaps@8'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xbde): undefined reference to `CreateCompatibleBitmap@12'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xbf5): undefined reference to `SelectObject@8'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xc18): undefined reference to `GetObjectA@12'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xcb2): undefined reference to `BitBlt@36'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xccd): undefined reference to `GetBitmapBits@12'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xd3c): undefined reference to `SelectObject@8'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xd47): undefined reference to `DeleteObject@4'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xd56): undefined reference to `DeleteDC@4'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xd61): undefined reference to `DeleteDC@4'
d:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: ../libcrypto.a(rand_win.o): bad reloc address 0x20 in section `.eh_frame'
d:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: final link
看来还少gdi,再次修改apps/makefile,Line 29,加入gdi lib:
LIBCRYPTO=-L.. -lws2_32 -lgdi32重新make,再次出现问题:
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x15c5): undefined reference to `CertGetCertificateContextProperty@16'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x162b): undefined reference to `CertGetCertificateContextProperty@16'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x1740): undefined reference to `CertGetCertificateContextProperty@16'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x1785): undefined reference to `CertGetCertificateContextProperty@16'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x1833): undefined reference to `CertFindCertificateInStore@24'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x184f): undefined reference to `CertEnumCertificatesInStore@8'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x1b1d): undefined reference to `CertOpenStore@20'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x1bc4): undefined reference to `CertFreeCertificateContext@4'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x1be4): undefined reference to `CertEnumCertificatesInStore@8'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x1c38): undefined reference to `CertCloseStore@8'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x2231): undefined reference to `CertFreeCertificateContext@4'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x224b): undefined reference to `CertCloseStore@8'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x22c2): undefined reference to `CertFreeCertificateContext@4'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x23ea): undefined reference to `CertEnumCertificatesInStore@8'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x24bd): undefined reference to `CertDuplicateCertificateContext@4'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x262a): undefined reference to `CertCloseStore@8'
d:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: ../libcrypto.a(e_capi.o): bad reloc address 0x0 in section `.data'
d:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: final link仍然缺少crypt32 lib,继续修改apps\Makefile,Line 29,改为:
LIBCRYPTO=-L.. -lcrypto -lws2_32 -lgdi32 -lcr
8683
ypt32重新make,apps编译完全通过。但在编译test时出现以上同样问题,修改test/Makefile的28行,同样改为
Good luck & Enjoy~
编译使用平台MingW,OpenSSL版本:openssl-1.0.0a
1. 编译过程
如果使用./Configure mingw或./config进行配置,在make时会出现如下错误:
gcc.exe: error: unrecognized command line option '-mno-cygwin'
导致编译无法继续,感觉是一个配置过程的bug,但是没找到好的办法解决。最终work的编译方法:
./Configure dist make clean make make install
编译正常执行。
2. 编译中在engines/e_capi.c出现编译错误
出现错误如下:
e_capi.c: In function 'capi_get_pkey':
e_capi.c:671:3: error: unknown type name 'DSSPUBKEY'
e_capi.c:674:9: error: 'DSSPUBKEY' undeclared (first use in this function)
e_capi.c:674:9: note: each undeclared identifier is reported only once for each function it appears in
e_capi.c:674:20: error: expected expression before ')' token
e_capi.c:675:9: error: request for member 'magic' in something not a structure or union
e_capi.c:678:38: error: request for member 'magic' in something not a structure or union
e_capi.c:683:16: error: request for member 'bitlen' in something not a structure or union
e_capi.c: In function 'capi_rsa_priv_dec':
e_capi.c:912:2: warning: passing argument 6 of 'CryptDecrypt' from incompatible pointer type [enabled by default]
In file included from e_capi.c:72:0:
d:\mingw\bin\../lib/gcc/mingw32/4.7.2/../../../../include/wincrypt.h:1209:23: note: expected 'PDWORD' but argument is of type 'int *'
e_capi.c: In function 'capi_dump_cert':
e_capi.c:1290:2: warning: passing argument 2 of 'd2i_X509' from incompatible pointer type [enabled by default]
In file included from ../include/openssl/engine.h:98:0,
from e_capi.c:106:
../include/openssl/x509.h:833:1: note: expected 'const unsigned char **' but argument is of type 'unsigned char **'
e_capi.c: In function 'capi_open_store':
e_capi.c:1328:25: error: 'CERT_STORE_PROV_SYSTEM_A' undeclared (first use in this function)
e_capi.c: In function 'capi_ctx_new':
e_capi.c:1529:5: error: 'CERT_STORE_READONLY_FLAG' undeclared (first use in this function)
e_capi.c: In function 'capi_load_ssl_client_cert':
e_capi.c:1633:3: warning: passing argument 2 of 'd2i_X509' from incompatible pointer type [enabled by default]
In file included from ../include/openssl/engine.h:98:0,
from e_capi.c:106:
../include/openssl/x509.h:833:1: note: expected 'const unsigned char **' but argument is of type 'const char **'
make[1]: *** [e_capi.o] Error 1
此为MingW平台下wincrypt定义不完整造成,看到网上一位网友的修改方法进行同样处理,问题得以解决,编译$MINGW_HOME/include/wincrypt.h,在1317行之后加入:
typedef struct _PUBKEY{ DWORD magic; DWORD bitlen; } DSSPUBKEY; #define CERT_STORE_PROV_SYSTEM_A ((LPCSTR)9) #define CERT_STORE_READONLY_FLAG 0x00008000 BOOL WINAPI CryptEnumProvidersA(DWORD, DWORD *, DWORD, DWORD *, LPSTR, DWORD *);重新make,通过。
3. apps,test链接出现问题
apps下的程序编译出现问题,已经不影响openSSL的使用,但是为了保证编译完整性,还是把问题解决掉,出现问题如下:
s_server.o:s_server.c:(.text+0x730): undefined reference to 'select@20' s_server.o:s_server.c:(.text+0x762): undefined reference to '__WSAFDIsSet@8' s_server.o:s_server.c:(.text+0x855): undefined reference to 'shutdown@8' s_server.o:s_server.c:(.text+0x860): undefined reference to 'closesocket@4' .....
很明显是WinSock lib没有在link列表中,于是在编译apps/Makefile,line 29,LIBCRYPTO改为:
LIBCRYPTO=-L.. -lws2_32
相关问题解决,重新make,libcrypto.a链接再次出现问题:
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xb86): undefined reference to `CreateDCA@16'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xb93): undefined reference to `CreateCompatibleDC@4'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xbaa): undefined reference to `GetDeviceCaps@8'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xbc1): undefined reference to `GetDeviceCaps@8'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xbde): undefined reference to `CreateCompatibleBitmap@12'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xbf5): undefined reference to `SelectObject@8'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xc18): undefined reference to `GetObjectA@12'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xcb2): undefined reference to `BitBlt@36'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xccd): undefined reference to `GetBitmapBits@12'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xd3c): undefined reference to `SelectObject@8'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xd47): undefined reference to `DeleteObject@4'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xd56): undefined reference to `DeleteDC@4'
../libcrypto.a(rand_win.o):rand_win.c:(.text+0xd61): undefined reference to `DeleteDC@4'
d:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: ../libcrypto.a(rand_win.o): bad reloc address 0x20 in section `.eh_frame'
d:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: final link
看来还少gdi,再次修改apps/makefile,Line 29,加入gdi lib:
LIBCRYPTO=-L.. -lws2_32 -lgdi32重新make,再次出现问题:
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x15c5): undefined reference to `CertGetCertificateContextProperty@16'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x162b): undefined reference to `CertGetCertificateContextProperty@16'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x1740): undefined reference to `CertGetCertificateContextProperty@16'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x1785): undefined reference to `CertGetCertificateContextProperty@16'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x1833): undefined reference to `CertFindCertificateInStore@24'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x184f): undefined reference to `CertEnumCertificatesInStore@8'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x1b1d): undefined reference to `CertOpenStore@20'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x1bc4): undefined reference to `CertFreeCertificateContext@4'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x1be4): undefined reference to `CertEnumCertificatesInStore@8'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x1c38): undefined reference to `CertCloseStore@8'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x2231): undefined reference to `CertFreeCertificateContext@4'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x224b): undefined reference to `CertCloseStore@8'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x22c2): undefined reference to `CertFreeCertificateContext@4'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x23ea): undefined reference to `CertEnumCertificatesInStore@8'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x24bd): undefined reference to `CertDuplicateCertificateContext@4'
../libcrypto.a(e_capi.o):e_capi.c:(.text+0x262a): undefined reference to `CertCloseStore@8'
d:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: ../libcrypto.a(e_capi.o): bad reloc address 0x0 in section `.data'
d:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: final link仍然缺少crypt32 lib,继续修改apps\Makefile,Line 29,改为:
LIBCRYPTO=-L.. -lcrypto -lws2_32 -lgdi32 -lcr
8683
ypt32重新make,apps编译完全通过。但在编译test时出现以上同样问题,修改test/Makefile的28行,同样改为
LIBCRYPTO=-L.. -lcrypto -lws2_32 -lgdi32 -lcrypt32再次重新make,编译全部通过,OpenSSL项目中所有项目编译完成。
Good luck & Enjoy~
相关文章推荐
- 使用mingw 对libcURL,openSSL,zLib交叉编译
- MinGW下编译openssl, json-c
- 使用mingw 对libcURL,openSSL,zLib交叉编译
- mingw编译protobuf和openssl
- 编译openssl-0.9.8a,用mingw,需要修改一下makefile
- 在Windows下用MinGW编译OpenSSL,及OpenSSL静态链接库libcrypto.a使用问题
- 使用mingw编译支持openssl 的 libcurl(windows下)
- windows下 Mingw (gcc)编译openssl
- Windows7下使用mingw编译openssl
- MinGW编译支持openssl-1.0.0a的libcurl-7.21.3
- mingw下编译openssl
- Windows7下使用mingw编译openssl
- openssl 0.9.8k在mingw中的编译
- 用MinGW编译openssl
- openssl-1.0.1用mingw编译
- 在Linux下使用MinGW静态交叉编译带有zlib的libcurl(包括交叉编译openssl,即--cross-compile-prefix=i686-w64-mingw32- mingw)
- windows下rabbitmq-c编译(带openssl、无需MinGW)
- 利用openssl管理证书及SSL编程第3部分:将MinGW编译的openssl dll导出def和lib供MSVC使用
- Openssl - Static libraries (w32, mingw) 以及对Qt静态编译时的设置
- MinGW编译OpenSSL