最近打算使用 crypto++ 5.6.0 , 由于我的机器上装了不同版本的 vc, 为了构建方便,写了 bjam 的构建脚本,可以方便的用不同的编译器编译库和DLL,十分方便。
jamroot 文件
- import os ;
- import pch ;
- import path ;
- import common ;
- default-build =
- debug release
- <threading>multi
- <runtime-link>static <runtime-link>shared
- ;
- if [ os.name ] = NT
- {
- default-build += <runtime-link>static <runtime-link>shared ;
- }
- # 这里的 <tag> 配合下面的 tag rule 可以定义输出的文件名,这里使用仿 boost 规则的库文件名,不过删除了版本信息
- project name
- : requirements <tag>@$(__name__).tag
- : build-dir bin
- : default-build $(default-build)
- ;
- # 按仿 boost 规则生成 lib 文件名
- rule tag ( name : type ? : property-set )
- {
- if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB
- {
- return [ common.format-name
- <base> <toolset> <threading> <runtime>
- : $(name) : $(type) : $(property-set) ] ;
- }
- }
在放 jamroot 的目录下创建 cryptopp 目录,并且放入 jamfile 文件
- project cryptopp
- : requirements
- <threading>multi
- <include>$(prjroot)
- <search>$(prjroot)
- <variant>release:<define>NDEBUG
- <define>USE_PRECOMPILED_HEADERS <define>WIN32
- : default-build release debug <link>shared <link>static <runtime-link>shared <runtime-link>static
- ;
- path-constant prjroot : ../../cryptopp ;
- # [ SHELL ( if not exist adhoc.cpp copy $(prjroot)/adhoc.cpp.proto $(prjroot)/adhoc.cpp ) ] ;
- local files = 3way.cpp adler32.cpp algebra.cpp algparam.cpp arc4.cpp asn.cpp authenc.cpp
- base32.cpp base64.cpp basecode.cpp bfinit.cpp blowfish.cpp blumshub.cpp camellia.cpp
- cast.cpp casts.cpp cbcmac.cpp ccm.cpp channels.cpp cmac.cpp cpu.cpp crc.cpp cryptlib.cpp
- default.cpp des.cpp dessp.cpp dh.cpp dh2.cpp dsa.cpp eax.cpp ec2n.cpp
- ecp.cpp elgamal.cpp emsa2.cpp esign.cpp files.cpp filters.cpp fips140.cpp
- fipstest.cpp gcm.cpp gf256.cpp gf2_32.cpp gf2n.cpp gfpcrypt.cpp gost.cpp gzip.cpp
- hex.cpp hmac.cpp hrtimer.cpp ida.cpp idea.cpp integer.cpp luc.cpp mars.cpp
- marss.cpp md2.cpp md4.cpp md5.cpp misc.cpp modes.cpp mqueue.cpp mqv.cpp nbtheory.cpp
- network.cpp oaep.cpp osrng.cpp panama.cpp pkcspad.cpp polynomi.cpp pssr.cpp
- pubkey.cpp queue.cpp rabin.cpp randpool.cpp rc2.cpp rc5.cpp rc6.cpp rdtables.cpp rijndael.cpp
- ripemd.cpp rng.cpp rsa.cpp rw.cpp safer.cpp salsa.cpp seal.cpp seed.cpp serpent.cpp sha.cpp
- shacal2.cpp shark.cpp sharkbox.cpp simple.cpp skipjack.cpp socketft.cpp sosemanuk.cpp square.cpp
- squaretb.cpp strciphr.cpp tea.cpp tftables.cpp tiger.cpp tigertab.cpp trdlocal.cpp ttmac.cpp
- twofish.cpp vmac.cpp wait.cpp wake.cpp whrlpool.cpp winpipes.cpp xtr.cpp xtrcrypt.cpp zdeflate.cpp
- zinflate.cpp zlib.cpp ;
- # 系统库列表
- local .system_lib = kernel32 user32 winspool Ws2_32 comdlg32 advapi32 shell32 ole32 oleaut32 uuid odbc32 odbccp32 ;
- lib $(.system_lib) ;
- lib cryptopp
- :
- [ obj dll_obj : $(prjroot)/dll.cpp ]
- [ obj iterhash_obj : $(prjroot)/iterhash.cpp ]
- [ cpp-pch cryptopp_pch : $(prjroot)/pch.h : <include>$(prjroot) ]
- $(prjroot)/$(files) $(.system_lib)
- :
- <link>shared:<define>CRYPTOPP_EXPORTS
- <link>shared:<define>CRYPTOPP_ENABLE_COMPLIANCE_WITH_FIPS_140_2=1
- :
- ;
- install stage
- : cryptopp
- : <location>../../stage/lib
- ;
这个脚本会自动创建不同版本的库和动态链接库,并且安装到 stage/lib 目录,使用 boost 的库命名方式。
- cryptopp-vc100-mt-gd.dll
- cryptopp-vc100-mt-gd.pdb
- cryptopp-vc100-mt-s.dll
- cryptopp-vc100-mt-sgd.dll
- cryptopp-vc100-mt-sgd.pdb
- cryptopp-vc100-mt.dll
- libcryptopp-vc100-mt-gd.lib
- libcryptopp-vc100-mt-s.lib
- libcryptopp-vc100-mt-sgd.lib
- libcryptopp-vc100-mt.lib
可以参考我的 博文: http://blog.csdn.net/jadedrip/archive/2007/10/11/1820368.aspx
另外,如果使用 vs 2010 来编译需要修改 pubkey.h 的 243 行为
- return HashIdentifier((const unsigned char*)NULL, 0);
还要把 zdeflate.cpp 389 行左右改成如下:
- #if defined(_MSC_VER) && _MSC_VER >= 1600
- std::mismatch
- #else
- # if defined(_STDEXT_BEGIN) && !(defined(_MSC_VER) && _MSC_VER < 1400) && !defined(_STLPORT_VERSION)
- stdext::unchecked_mismatch
- # else
- std::mismatch
- # endif
- #endif