使用 Qt 程序构建 crypto++ 时出现链接器错误
Linker error while building crypto++ with Qt program
问题
我将所有 crypto++ 的头文件和源文件(.h,.cpp) 添加到我的 Qt5 项目中。
我构建了它,它给了我十个 link 个错误。
背景
我使用的是Qt5.9.7版本
编译器为msvc2017-64bit.
crypto++ 是最新的 8.0.0 版本。
错误
test.obj:-1: error: LNK2005: main already defined in main.obj
gcm.obj:-1: error: LNK2019: unresolved external symbol GCM_AuthenticateBlocks_2K_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::GCM_Base::AuthenticateBlocks(unsigned char const *,unsigned __int64)" (?AuthenticateBlocks@GCM_Base@CryptoPP@@MEAA_KPEBE_K@Z)
gcm.obj:-1: error: LNK2019: unresolved external symbol GCM_AuthenticateBlocks_64K_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::GCM_Base::AuthenticateBlocks(unsigned char const *,unsigned __int64)" (?AuthenticateBlocks@GCM_Base@CryptoPP@@MEAA_KPEBE_K@Z)
integer.obj:-1: error: LNK2019: unresolved external symbol Baseline_Add referenced in function "int __cdecl CryptoPP::Add(unsigned __int64 *,unsigned __int64 const *,unsigned __int64 const *,unsigned __int64)" (?Add@CryptoPP@@YAHPEA_KPEB_K1_K@Z)
integer.obj:-1: error: LNK2019: unresolved external symbol Baseline_Sub referenced in function "int __cdecl CryptoPP::Subtract(unsigned __int64 *,unsigned __int64 const *,unsigned __int64 const *,unsigned __int64)" (?Subtract@CryptoPP@@YAHPEA_KPEB_K1_K@Z)
rdrand.obj:-1: error: LNK2019: unresolved external symbol MASM_RDRAND_GenerateBlock referenced in function "public: virtual void __cdecl CryptoPP::RDRAND::GenerateBlock(unsigned char *,unsigned __int64)" (?GenerateBlock@RDRAND@CryptoPP@@UEAAXPEAE_K@Z)
rdrand.obj:-1: error: LNK2019: unresolved external symbol MASM_RDSEED_GenerateBlock referenced in function "public: virtual void __cdecl CryptoPP::RDSEED::GenerateBlock(unsigned char *,unsigned __int64)" (?GenerateBlock@RDSEED@CryptoPP@@UEAAXPEAE_K@Z)
rijndael.obj:-1: error: LNK2019: unresolved external symbol Rijndael_Enc_AdvancedProcessBlocks_SSE2 referenced in function "public: virtual unsigned __int64 __cdecl CryptoPP::Rijndael::Enc::AdvancedProcessBlocks(unsigned char const *,unsigned char const *,unsigned char *,unsigned __int64,unsigned int)const " (?AdvancedProcessBlocks@Enc@Rijndael@CryptoPP@@UEBA_KPEBE0PEAE_KI@Z)
salsa.obj:-1: error: LNK2019: unresolved external symbol Salsa20_OperateKeystream referenced in function "protected: virtual void __cdecl CryptoPP::Salsa20_Policy::OperateKeystream(enum CryptoPP::KeystreamOperation,unsigned char *,unsigned char const *,unsigned __int64)" (?OperateKeystream@Salsa20_Policy@CryptoPP@@MEAAXW4KeystreamOperation@2@PEAEPEBE_K@Z)
sha.obj:-1: error: LNK2019: unresolved external symbol SHA256_HashMultipleBlocks_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::SHA256::HashMultipleBlocks(unsigned int const *,unsigned __int64)" (?HashMultipleBlocks@SHA256@CryptoPP@@MEAA_KPEBI_K@Z)
sosemanuk.obj:-1: error: LNK2019: unresolved external symbol Sosemanuk_OperateKeystream referenced in function "protected: virtual void __cdecl CryptoPP::SosemanukPolicy::OperateKeystream(enum CryptoPP::KeystreamOperation,unsigned char *,unsigned char const *,unsigned __int64)" (?OperateKeystream@SosemanukPolicy@CryptoPP@@MEAAXW4KeystreamOperation@2@PEAEPEBE_K@Z)
gcm.obj:-1: error: LNK2019: unresolved external symbol GCM_AuthenticateBlocks_2K_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::GCM_Base::AuthenticateBlocks(unsigned char const *,unsigned __int64)" (?AuthenticateBlocks@GCM_Base@CryptoPP@@MEAA_KPEBE_K@Z)
gcm.obj:-1: error: LNK2019: unresolved external symbol GCM_AuthenticateBlocks_64K_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::GCM_Base::AuthenticateBlocks(unsigned char const *,unsigned __int64)" (?AuthenticateBlocks@GCM_Base@CryptoPP@@MEAA_KPEBE_K@Z)
integer.obj:-1: error: LNK2019: unresolved external symbol Baseline_Add referenced in function "int __cdecl CryptoPP::Add(unsigned __int64 *,unsigned __int64 const *,unsigned __int64 const *,unsigned __int64)" (?Add@CryptoPP@@YAHPEA_KPEB_K1_K@Z)
integer.obj:-1: error: LNK2019: unresolved external symbol Baseline_Sub referenced in function "int __cdecl CryptoPP::Subtract(unsigned __int64 *,unsigned __int64 const *,unsigned __int64 const *,unsigned __int64)" (?Subtract@CryptoPP@@YAHPEA_KPEB_K1_K@Z)
rdrand.obj:-1: error: LNK2019: unresolved external symbol MASM_RDRAND_GenerateBlock referenced in function "public: virtual void __cdecl CryptoPP::RDRAND::GenerateBlock(unsigned char *,unsigned __int64)" (?GenerateBlock@RDRAND@CryptoPP@@UEAAXPEAE_K@Z)
rdrand.obj:-1: error: LNK2019: unresolved external symbol MASM_RDSEED_GenerateBlock referenced in function "public: virtual void __cdecl CryptoPP::RDSEED::GenerateBlock(unsigned char *,unsigned __int64)" (?GenerateBlock@RDSEED@CryptoPP@@UEAAXPEAE_K@Z)
rijndael.obj:-1: error: LNK2019: unresolved external symbol Rijndael_Enc_AdvancedProcessBlocks_SSE2 referenced in function "public: virtual unsigned __int64 __cdecl CryptoPP::Rijndael::Enc::AdvancedProcessBlocks(unsigned char const *,unsigned char const *,unsigned char *,unsigned __int64,unsigned int)const " (?AdvancedProcessBlocks@Enc@Rijndael@CryptoPP@@UEBA_KPEBE0PEAE_KI@Z)
salsa.obj:-1: error: LNK2019: unresolved external symbol Salsa20_OperateKeystream referenced in function "protected: virtual void __cdecl CryptoPP::Salsa20_Policy::OperateKeystream(enum CryptoPP::KeystreamOperation,unsigned char *,unsigned char const *,unsigned __int64)" (?OperateKeystream@Salsa20_Policy@CryptoPP@@MEAAXW4KeystreamOperation@2@PEAEPEBE_K@Z)
sha.obj:-1: error: LNK2019: unresolved external symbol SHA256_HashMultipleBlocks_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::SHA256::HashMultipleBlocks(unsigned int const *,unsigned __int64)" (?HashMultipleBlocks@SHA256@CryptoPP@@MEAA_KPEBI_K@Z)
sosemanuk.obj:-1: error: LNK2019: unresolved external symbol Sosemanuk_OperateKeystream referenced in function "protected: virtual void __cdecl CryptoPP::SosemanukPolicy::OperateKeystream(enum CryptoPP::KeystreamOperation,unsigned char *,unsigned char const *,unsigned __int64)" (?OperateKeystream@SosemanukPolicy@CryptoPP@@MEAAXW4KeystreamOperation@2@PEAEPEBE_K@Z)
这些函数在MASM源文件中,如x64dll.asm
, x64masm.asm
and rdrand.asm
。您应该添加源文件或使用 -DCRYPTOPP_DISABLE_ASM
.
添加丢失的源文件后,我怀疑您会遇到更多麻烦,因为您可能没有添加 Crypto++ Visual Studio 解决方案和项目文件中存在的预处理器宏。您可以从 cryptlib.vcxproj
(和 vcxproj 朋友)处获得它们。寻找 PreprocessorDefinitions
标签。
你或许应该退后一步。使用 Visual Studio 解决方案和项目文件构建库。您只需要构建 cryptlib
项目、调试和发布配置。然后,将 Crypto++ 库作为链接器选项添加到您的 Qt 项目中。
另见 Visual Studio on the Crypto++ wiki. Pay particular attention to the section Runtime Linking。因为您使用的是 Qt,所以您需要切换到动态运行时链接。维基页面告诉您如何操作。
关于使用 Qt 和您的程序构建 Crypto++,您应该了解 Visual Studio 解决方案中有多个项目。当您说 "added all header and source files" 时,您同时添加了库 (cryptlib.vcxproj
) 和测试套件 (cryptest.vcxproj
)。您只需要库文件,而不需要测试文件。
您的 Qt 程序提供了 main
函数,而 Crypto++ 测试套件提供了 main
,这就是您遇到以下问题的原因:
test.obj:-1: error: LNK2005: main already defined in main.obj
您可以通过跳转到 Linux 然后 make sources
来获取头文件和源文件的列表。您对 Library sources
和 Library headers
.
感兴趣
$ make sources
***** Library sources *****
cryptlib.cpp cpu.cpp integer.cpp 3way.cpp adler32.cpp algebra.cpp algparam.cpp a
rc4.cpp aria.cpp aria_simd.cpp ariatab.cpp asn.cpp authenc.cpp base32.cpp base64
.cpp basecode.cpp bfinit.cpp blake2.cpp blake2b_simd.cpp blake2s_simd.cpp blowfi
sh.cpp blumshub.cpp camellia.cpp cast.cpp casts.cpp cbcmac.cpp ccm.cpp chacha.cp
p chacha_avx.cpp chacha_simd.cpp cham.cpp cham_simd.cpp channels.cpp cmac.cpp cr
c.cpp crc_simd.cpp darn.cpp default.cpp des.cpp dessp.cpp dh.cpp dh2.cpp dll.cpp
donna_32.cpp donna_64.cpp donna_sse.cpp dsa.cpp eax.cpp ec2n.cpp eccrypto.cpp e
cp.cpp elgamal.cpp emsa2.cpp eprecomp.cpp esign.cpp files.cpp filters.cpp fips14
0.cpp fipstest.cpp gcm.cpp gcm_simd.cpp gf256.cpp gf2_32.cpp gf2n.cpp gf2n_simd.
cpp gfpcrypt.cpp gost.cpp gzip.cpp hc128.cpp hc256.cpp hex.cpp hight.cpp hmac.cp
p hrtimer.cpp ida.cpp idea.cpp iterhash.cpp kalyna.cpp kalynatab.cpp keccak.cpp
keccakc.cpp lea.cpp lea_simd.cpp lsh.cpp luc.cpp mars.cpp marss.cpp md2.cpp md4.
cpp md5.cpp misc.cpp modes.cpp mqueue.cpp mqv.cpp nbtheory.cpp neon_simd.cpp oae
p.cpp ospstore.cpp osrng.cpp padlkrng.cpp panama.cpp pkcspad.cpp poly1305.cpp po
lynomi.cpp ppc_power7.cpp ppc_power8.cpp ppc_power9.cpp ppc_simd.cpp pssr.cpp pu
bkey.cpp queue.cpp rabbit.cpp rabin.cpp randpool.cpp rc2.cpp rc5.cpp rc6.cpp rdr
and.cpp rdtables.cpp rijndael.cpp rijndael_simd.cpp ripemd.cpp rng.cpp rsa.cpp r
w.cpp safer.cpp salsa.cpp scrypt.cpp seal.cpp seed.cpp serpent.cpp sha.cpp sha3.
cpp sha_simd.cpp shacal2.cpp shacal2_simd.cpp shark.cpp sharkbox.cpp simeck.cpp
simeck_simd.cpp simon.cpp simon128_simd.cpp simon64_simd.cpp skipjack.cpp sm3.cp
p sm4.cpp sm4_simd.cpp sosemanuk.cpp speck.cpp speck128_simd.cpp speck64_simd.cp
p square.cpp squaretb.cpp sse_simd.cpp strciphr.cpp tea.cpp tftables.cpp threefi
sh.cpp tiger.cpp tigertab.cpp ttmac.cpp tweetnacl.cpp twofish.cpp vmac.cpp wake.
cpp whrlpool.cpp xed25519.cpp xtr.cpp xtrcrypt.cpp zdeflate.cpp zinflate.cpp zli
b.cpp
***** Library headers *****
3way.h adler32.h adv_simd.h aes.h aes_armv4.h algebra.h algparam.h androidpay.h
arc4.h argnames.h aria.h arm_simd.h asn.h authenc.h base32.h base64.h basecode.h
blake2.h blowfish.h blumshub.h camellia.h cast.h cbcmac.h ccm.h chacha.h cham.h
channels.h cmac.h config.h cpu.h crc.h cryptlib.h darn.h default.h des.h dh.h d
h2.h dll.h dmac.h donna.h donna_32.h donna_64.h donna_sse.h drbg.h dsa.h eax.h e
c2n.h eccrypto.h ecp.h ecpoint.h elgamal.h emsa2.h eprecomp.h equihash.h esign.h
fhmqv.h files.h filters.h fips140.h fltrimpl.h gcm.h gf256.h gf2_32.h gf2n.h gf
pcrypt.h gost.h gzip.h hashfwd.h hc128.h hc256.h hex.h hight.h hkdf.h hmac.h hmq
v.h hrtimer.h ida.h idea.h integer.h iterhash.h kalyna.h keccak.h keccakc.h lea.
h lsh.h lubyrack.h luc.h mars.h md2.h md4.h md5.h mdc.h mersenne.h misc.h modari
th.h modes.h modexppc.h mqueue.h mqv.h naclite.h nbtheory.h nr.h oaep.h oids.h o
spstore.h osrng.h ossig.h padlkrng.h panama.h pch.h pem.h pkcspad.h poly1305.h p
olynomi.h ppc_simd.h pssr.h pubkey.h pwdbased.h queue.h rabbit.h rabin.h randpoo
l.h rc2.h rc5.h rc6.h rdrand.h rijndael.h ripemd.h rng.h rsa.h rw.h safer.h sals
a.h scrypt.h seal.h secblock.h seckey.h seed.h serpent.h serpentp.h sha.h sha3.h
shacal2.h shark.h simeck.h simon.h simple.h siphash.h skipjack.h sm3.h sm4.h sm
artptr.h sosemanuk.h speck.h square.h stdcpp.h strciphr.h tea.h threefish.h tige
r.h trap.h trunhash.h ttmac.h tweetnacl.h twofish.h vmac.h wake.h whrlpool.h wor
ds.h xed25519.h xtr.h xtrcrypt.h zdeflate.h zinflate.h zlib.h
***** Test sources *****
adhoc.cpp test.cpp bench1.cpp bench2.cpp bench3.cpp datatest.cpp dlltest.cpp fip
salgt.cpp validat0.cpp validat1.cpp validat2.cpp validat3.cpp validat4.cpp valid
at5.cpp validat6.cpp validat7.cpp validat8.cpp validat9.cpp validat10.cpp regtes
t1.cpp regtest2.cpp regtest3.cpp regtest4.cpp
***** Test headers *****
bench.h factory.h validate.h
问题
我将所有 crypto++ 的头文件和源文件(.h,.cpp) 添加到我的 Qt5 项目中。
我构建了它,它给了我十个 link 个错误。
背景
我使用的是Qt5.9.7版本
编译器为msvc2017-64bit.
crypto++ 是最新的 8.0.0 版本。
错误
test.obj:-1: error: LNK2005: main already defined in main.obj
gcm.obj:-1: error: LNK2019: unresolved external symbol GCM_AuthenticateBlocks_2K_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::GCM_Base::AuthenticateBlocks(unsigned char const *,unsigned __int64)" (?AuthenticateBlocks@GCM_Base@CryptoPP@@MEAA_KPEBE_K@Z)
gcm.obj:-1: error: LNK2019: unresolved external symbol GCM_AuthenticateBlocks_64K_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::GCM_Base::AuthenticateBlocks(unsigned char const *,unsigned __int64)" (?AuthenticateBlocks@GCM_Base@CryptoPP@@MEAA_KPEBE_K@Z)
integer.obj:-1: error: LNK2019: unresolved external symbol Baseline_Add referenced in function "int __cdecl CryptoPP::Add(unsigned __int64 *,unsigned __int64 const *,unsigned __int64 const *,unsigned __int64)" (?Add@CryptoPP@@YAHPEA_KPEB_K1_K@Z)
integer.obj:-1: error: LNK2019: unresolved external symbol Baseline_Sub referenced in function "int __cdecl CryptoPP::Subtract(unsigned __int64 *,unsigned __int64 const *,unsigned __int64 const *,unsigned __int64)" (?Subtract@CryptoPP@@YAHPEA_KPEB_K1_K@Z)
rdrand.obj:-1: error: LNK2019: unresolved external symbol MASM_RDRAND_GenerateBlock referenced in function "public: virtual void __cdecl CryptoPP::RDRAND::GenerateBlock(unsigned char *,unsigned __int64)" (?GenerateBlock@RDRAND@CryptoPP@@UEAAXPEAE_K@Z)
rdrand.obj:-1: error: LNK2019: unresolved external symbol MASM_RDSEED_GenerateBlock referenced in function "public: virtual void __cdecl CryptoPP::RDSEED::GenerateBlock(unsigned char *,unsigned __int64)" (?GenerateBlock@RDSEED@CryptoPP@@UEAAXPEAE_K@Z)
rijndael.obj:-1: error: LNK2019: unresolved external symbol Rijndael_Enc_AdvancedProcessBlocks_SSE2 referenced in function "public: virtual unsigned __int64 __cdecl CryptoPP::Rijndael::Enc::AdvancedProcessBlocks(unsigned char const *,unsigned char const *,unsigned char *,unsigned __int64,unsigned int)const " (?AdvancedProcessBlocks@Enc@Rijndael@CryptoPP@@UEBA_KPEBE0PEAE_KI@Z)
salsa.obj:-1: error: LNK2019: unresolved external symbol Salsa20_OperateKeystream referenced in function "protected: virtual void __cdecl CryptoPP::Salsa20_Policy::OperateKeystream(enum CryptoPP::KeystreamOperation,unsigned char *,unsigned char const *,unsigned __int64)" (?OperateKeystream@Salsa20_Policy@CryptoPP@@MEAAXW4KeystreamOperation@2@PEAEPEBE_K@Z)
sha.obj:-1: error: LNK2019: unresolved external symbol SHA256_HashMultipleBlocks_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::SHA256::HashMultipleBlocks(unsigned int const *,unsigned __int64)" (?HashMultipleBlocks@SHA256@CryptoPP@@MEAA_KPEBI_K@Z)
sosemanuk.obj:-1: error: LNK2019: unresolved external symbol Sosemanuk_OperateKeystream referenced in function "protected: virtual void __cdecl CryptoPP::SosemanukPolicy::OperateKeystream(enum CryptoPP::KeystreamOperation,unsigned char *,unsigned char const *,unsigned __int64)" (?OperateKeystream@SosemanukPolicy@CryptoPP@@MEAAXW4KeystreamOperation@2@PEAEPEBE_K@Z)
gcm.obj:-1: error: LNK2019: unresolved external symbol GCM_AuthenticateBlocks_2K_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::GCM_Base::AuthenticateBlocks(unsigned char const *,unsigned __int64)" (?AuthenticateBlocks@GCM_Base@CryptoPP@@MEAA_KPEBE_K@Z)
gcm.obj:-1: error: LNK2019: unresolved external symbol GCM_AuthenticateBlocks_64K_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::GCM_Base::AuthenticateBlocks(unsigned char const *,unsigned __int64)" (?AuthenticateBlocks@GCM_Base@CryptoPP@@MEAA_KPEBE_K@Z)
integer.obj:-1: error: LNK2019: unresolved external symbol Baseline_Add referenced in function "int __cdecl CryptoPP::Add(unsigned __int64 *,unsigned __int64 const *,unsigned __int64 const *,unsigned __int64)" (?Add@CryptoPP@@YAHPEA_KPEB_K1_K@Z)
integer.obj:-1: error: LNK2019: unresolved external symbol Baseline_Sub referenced in function "int __cdecl CryptoPP::Subtract(unsigned __int64 *,unsigned __int64 const *,unsigned __int64 const *,unsigned __int64)" (?Subtract@CryptoPP@@YAHPEA_KPEB_K1_K@Z)
rdrand.obj:-1: error: LNK2019: unresolved external symbol MASM_RDRAND_GenerateBlock referenced in function "public: virtual void __cdecl CryptoPP::RDRAND::GenerateBlock(unsigned char *,unsigned __int64)" (?GenerateBlock@RDRAND@CryptoPP@@UEAAXPEAE_K@Z)
rdrand.obj:-1: error: LNK2019: unresolved external symbol MASM_RDSEED_GenerateBlock referenced in function "public: virtual void __cdecl CryptoPP::RDSEED::GenerateBlock(unsigned char *,unsigned __int64)" (?GenerateBlock@RDSEED@CryptoPP@@UEAAXPEAE_K@Z)
rijndael.obj:-1: error: LNK2019: unresolved external symbol Rijndael_Enc_AdvancedProcessBlocks_SSE2 referenced in function "public: virtual unsigned __int64 __cdecl CryptoPP::Rijndael::Enc::AdvancedProcessBlocks(unsigned char const *,unsigned char const *,unsigned char *,unsigned __int64,unsigned int)const " (?AdvancedProcessBlocks@Enc@Rijndael@CryptoPP@@UEBA_KPEBE0PEAE_KI@Z)
salsa.obj:-1: error: LNK2019: unresolved external symbol Salsa20_OperateKeystream referenced in function "protected: virtual void __cdecl CryptoPP::Salsa20_Policy::OperateKeystream(enum CryptoPP::KeystreamOperation,unsigned char *,unsigned char const *,unsigned __int64)" (?OperateKeystream@Salsa20_Policy@CryptoPP@@MEAAXW4KeystreamOperation@2@PEAEPEBE_K@Z)
sha.obj:-1: error: LNK2019: unresolved external symbol SHA256_HashMultipleBlocks_SSE2 referenced in function "protected: virtual unsigned __int64 __cdecl CryptoPP::SHA256::HashMultipleBlocks(unsigned int const *,unsigned __int64)" (?HashMultipleBlocks@SHA256@CryptoPP@@MEAA_KPEBI_K@Z)
sosemanuk.obj:-1: error: LNK2019: unresolved external symbol Sosemanuk_OperateKeystream referenced in function "protected: virtual void __cdecl CryptoPP::SosemanukPolicy::OperateKeystream(enum CryptoPP::KeystreamOperation,unsigned char *,unsigned char const *,unsigned __int64)" (?OperateKeystream@SosemanukPolicy@CryptoPP@@MEAAXW4KeystreamOperation@2@PEAEPEBE_K@Z)
这些函数在MASM源文件中,如x64dll.asm
, x64masm.asm
and rdrand.asm
。您应该添加源文件或使用 -DCRYPTOPP_DISABLE_ASM
.
添加丢失的源文件后,我怀疑您会遇到更多麻烦,因为您可能没有添加 Crypto++ Visual Studio 解决方案和项目文件中存在的预处理器宏。您可以从 cryptlib.vcxproj
(和 vcxproj 朋友)处获得它们。寻找 PreprocessorDefinitions
标签。
你或许应该退后一步。使用 Visual Studio 解决方案和项目文件构建库。您只需要构建 cryptlib
项目、调试和发布配置。然后,将 Crypto++ 库作为链接器选项添加到您的 Qt 项目中。
另见 Visual Studio on the Crypto++ wiki. Pay particular attention to the section Runtime Linking。因为您使用的是 Qt,所以您需要切换到动态运行时链接。维基页面告诉您如何操作。
关于使用 Qt 和您的程序构建 Crypto++,您应该了解 Visual Studio 解决方案中有多个项目。当您说 "added all header and source files" 时,您同时添加了库 (cryptlib.vcxproj
) 和测试套件 (cryptest.vcxproj
)。您只需要库文件,而不需要测试文件。
您的 Qt 程序提供了 main
函数,而 Crypto++ 测试套件提供了 main
,这就是您遇到以下问题的原因:
test.obj:-1: error: LNK2005: main already defined in main.obj
您可以通过跳转到 Linux 然后 make sources
来获取头文件和源文件的列表。您对 Library sources
和 Library headers
.
$ make sources
***** Library sources *****
cryptlib.cpp cpu.cpp integer.cpp 3way.cpp adler32.cpp algebra.cpp algparam.cpp a
rc4.cpp aria.cpp aria_simd.cpp ariatab.cpp asn.cpp authenc.cpp base32.cpp base64
.cpp basecode.cpp bfinit.cpp blake2.cpp blake2b_simd.cpp blake2s_simd.cpp blowfi
sh.cpp blumshub.cpp camellia.cpp cast.cpp casts.cpp cbcmac.cpp ccm.cpp chacha.cp
p chacha_avx.cpp chacha_simd.cpp cham.cpp cham_simd.cpp channels.cpp cmac.cpp cr
c.cpp crc_simd.cpp darn.cpp default.cpp des.cpp dessp.cpp dh.cpp dh2.cpp dll.cpp
donna_32.cpp donna_64.cpp donna_sse.cpp dsa.cpp eax.cpp ec2n.cpp eccrypto.cpp e
cp.cpp elgamal.cpp emsa2.cpp eprecomp.cpp esign.cpp files.cpp filters.cpp fips14
0.cpp fipstest.cpp gcm.cpp gcm_simd.cpp gf256.cpp gf2_32.cpp gf2n.cpp gf2n_simd.
cpp gfpcrypt.cpp gost.cpp gzip.cpp hc128.cpp hc256.cpp hex.cpp hight.cpp hmac.cp
p hrtimer.cpp ida.cpp idea.cpp iterhash.cpp kalyna.cpp kalynatab.cpp keccak.cpp
keccakc.cpp lea.cpp lea_simd.cpp lsh.cpp luc.cpp mars.cpp marss.cpp md2.cpp md4.
cpp md5.cpp misc.cpp modes.cpp mqueue.cpp mqv.cpp nbtheory.cpp neon_simd.cpp oae
p.cpp ospstore.cpp osrng.cpp padlkrng.cpp panama.cpp pkcspad.cpp poly1305.cpp po
lynomi.cpp ppc_power7.cpp ppc_power8.cpp ppc_power9.cpp ppc_simd.cpp pssr.cpp pu
bkey.cpp queue.cpp rabbit.cpp rabin.cpp randpool.cpp rc2.cpp rc5.cpp rc6.cpp rdr
and.cpp rdtables.cpp rijndael.cpp rijndael_simd.cpp ripemd.cpp rng.cpp rsa.cpp r
w.cpp safer.cpp salsa.cpp scrypt.cpp seal.cpp seed.cpp serpent.cpp sha.cpp sha3.
cpp sha_simd.cpp shacal2.cpp shacal2_simd.cpp shark.cpp sharkbox.cpp simeck.cpp
simeck_simd.cpp simon.cpp simon128_simd.cpp simon64_simd.cpp skipjack.cpp sm3.cp
p sm4.cpp sm4_simd.cpp sosemanuk.cpp speck.cpp speck128_simd.cpp speck64_simd.cp
p square.cpp squaretb.cpp sse_simd.cpp strciphr.cpp tea.cpp tftables.cpp threefi
sh.cpp tiger.cpp tigertab.cpp ttmac.cpp tweetnacl.cpp twofish.cpp vmac.cpp wake.
cpp whrlpool.cpp xed25519.cpp xtr.cpp xtrcrypt.cpp zdeflate.cpp zinflate.cpp zli
b.cpp
***** Library headers *****
3way.h adler32.h adv_simd.h aes.h aes_armv4.h algebra.h algparam.h androidpay.h
arc4.h argnames.h aria.h arm_simd.h asn.h authenc.h base32.h base64.h basecode.h
blake2.h blowfish.h blumshub.h camellia.h cast.h cbcmac.h ccm.h chacha.h cham.h
channels.h cmac.h config.h cpu.h crc.h cryptlib.h darn.h default.h des.h dh.h d
h2.h dll.h dmac.h donna.h donna_32.h donna_64.h donna_sse.h drbg.h dsa.h eax.h e
c2n.h eccrypto.h ecp.h ecpoint.h elgamal.h emsa2.h eprecomp.h equihash.h esign.h
fhmqv.h files.h filters.h fips140.h fltrimpl.h gcm.h gf256.h gf2_32.h gf2n.h gf
pcrypt.h gost.h gzip.h hashfwd.h hc128.h hc256.h hex.h hight.h hkdf.h hmac.h hmq
v.h hrtimer.h ida.h idea.h integer.h iterhash.h kalyna.h keccak.h keccakc.h lea.
h lsh.h lubyrack.h luc.h mars.h md2.h md4.h md5.h mdc.h mersenne.h misc.h modari
th.h modes.h modexppc.h mqueue.h mqv.h naclite.h nbtheory.h nr.h oaep.h oids.h o
spstore.h osrng.h ossig.h padlkrng.h panama.h pch.h pem.h pkcspad.h poly1305.h p
olynomi.h ppc_simd.h pssr.h pubkey.h pwdbased.h queue.h rabbit.h rabin.h randpoo
l.h rc2.h rc5.h rc6.h rdrand.h rijndael.h ripemd.h rng.h rsa.h rw.h safer.h sals
a.h scrypt.h seal.h secblock.h seckey.h seed.h serpent.h serpentp.h sha.h sha3.h
shacal2.h shark.h simeck.h simon.h simple.h siphash.h skipjack.h sm3.h sm4.h sm
artptr.h sosemanuk.h speck.h square.h stdcpp.h strciphr.h tea.h threefish.h tige
r.h trap.h trunhash.h ttmac.h tweetnacl.h twofish.h vmac.h wake.h whrlpool.h wor
ds.h xed25519.h xtr.h xtrcrypt.h zdeflate.h zinflate.h zlib.h
***** Test sources *****
adhoc.cpp test.cpp bench1.cpp bench2.cpp bench3.cpp datatest.cpp dlltest.cpp fip
salgt.cpp validat0.cpp validat1.cpp validat2.cpp validat3.cpp validat4.cpp valid
at5.cpp validat6.cpp validat7.cpp validat8.cpp validat9.cpp validat10.cpp regtes
t1.cpp regtest2.cpp regtest3.cpp regtest4.cpp
***** Test headers *****
bench.h factory.h validate.h