Visual Studio 2010下生成Crypto++ lib

关键字:VS2010 Cryptopp Crypto++ 5.6 build utility compile error

 

Crypto++是一个密码学的SDK开发包,有关它的信息可以访问以下两个网站:

http://www.cryptopp.com/

http://www.cryptopp.com/wiki/Main_Page

但Crypto++ Library 5.6.0在VS2010下无法Build生成cryptlib.lib,编译链接时提示如下错误:

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2440: 'initializing' : cannot convert from 'int' to 'const unsigned char *'

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2439: 'std::_Pair_base<_Ty1,_Ty2>::first' : member could not be initialized

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2440: 'initializing' : cannot convert from 'int' to 'const unsigned char *'

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2439: 'std::_Pair_base<_Ty1,_Ty2>::first' : member could not be initialized

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2440: 'initializing' : cannot convert from 'int' to 'const unsigned char *'

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2439: 'std::_Pair_base<_Ty1,_Ty2>::first' : member could not be initialized

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2440: 'initializing' : cannot convert from 'int' to 'const unsigned char *'

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2439: 'std::_Pair_base<_Ty1,_Ty2>::first' : member could not be initialized

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2440: 'initializing' : cannot convert from 'int' to 'const unsigned char *'

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2439: 'std::_Pair_base<_Ty1,_Ty2>::first' : member could not be initialized

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2440: 'initializing' : cannot convert from 'int' to 'const unsigned char *'

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2439: 'std::_Pair_base<_Ty1,_Ty2>::first' : member could not be initialized

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2440: 'initializing' : cannot convert from 'int' to 'const unsigned char *'

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2439: 'std::_Pair_base<_Ty1,_Ty2>::first' : member could not be initialized

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2440: 'initializing' : cannot convert from 'int' to 'const unsigned char *'

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2439: 'std::_Pair_base<_Ty1,_Ty2>::first' : member could not be initialized

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2440: 'initializing' : cannot convert from 'int' to 'const unsigned char *'

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2439: 'std::_Pair_base<_Ty1,_Ty2>::first' : member could not be initialized

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2440: 'initializing' : cannot convert from 'int' to 'const unsigned char *'

1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): error C2439: 'std::_Pair_base<_Ty1,_Ty2>::first' : member could not be initialized

1>zdeflate.cpp(390): error C2653: 'stdext' : is not a class or namespace name

1>zdeflate.cpp(394): error C2228: left of '.first' must have class/struct/union

1>zdeflate.cpp(394): error C3861: 'unchecked_mismatch': identifier not found

找了很久,当时网上仅有一个地方给出了答案:

http://groups.google.com/group/cryptopp-users/browse_thread/thread/714f3ec6287a50b1

但这个网站不知什么原因在国内有些地方无法访问,通过部分代理(如http://www.7daili.com/)才能访问到,在这里做个总结,希望对大家能有所帮助。

 

使用VS2010打开Crypto++ Library 5.6.0时,一定要从"cryptest.dsw"打开,VS2010通过自动转换(conversion)可以打开Solution,如果从"cryptest.sln"打开,VS2010转换成10.0的Solution会提示报错,并且无法使用工程,如下图:

通过修改Crypto++ Library 5.6.0的2个地方,就可以解决以上问题,修改地方如下(红字为添加的代码):

1.

文件:pubkey.h

行数:243

原始代码:return HashIdentifier(NULL, 0);

修改代码:return HashIdentifier((const byte*)NULL, 0);

2.

文件:zdeflate.cpp

行数:389

原始代码:#if defined(_STDEXT_BEGIN) && !(defined(_MSC_VER) && _MSC_VER < 1400) && !defined(_STLPORT_VERSION)

修改代码:#if defined(_STDEXT_BEGIN) && !(defined(_MSC_VER) && (_MSC_VER < 1400 || _MSC_VER >= 1600)) && !defined(_STLPORT_VERSION)

然后,再重新build就可以成功生成cryptlib.lib了(Debug和Release下)。

 

注意:本文仅提供生成cryptlib.lib的方法,其它工程暂时无法在VS2010下成功编译链接。

posted @ 2010-07-29 11:48 cxun 阅读(...) 评论(...) 编辑 收藏