问题
我将所有crypto ++的头文件和源文件(.h,.cpp)添加到我的Qt5项目中。 我建立了它,它给了我十个链接错误。
背景
我正在使用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)
答案 0 :(得分:3)
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
和rdrand.asm
。您应该添加源文件或使用-DCRYPTOPP_DISABLE_ASM
。
一旦添加了丢失的源文件,我怀疑您会遇到更多麻烦,因为您可能未添加Crypto ++ Visual Studio解决方案和项目文件中存在的预处理器宏。您可以从cryptlib.vcxproj
(和vcxproj朋友)那里获得它们。寻找PreprocessorDefinitions
标签。
您可能应该退后一步。使用Visual Studio解决方案和项目文件构建库。您只需要构建cryptlib
项目,调试和发布配置。然后,将Crypto ++库作为链接器选项添加到Qt项目中。
另请参见Crypto ++ Wiki上的Visual Studio。请特别注意Runtime Linking部分。因为使用的是Qt,所以需要切换到“动态运行时链接”。 Wiki页面告诉您如何操作。
关于使用Qt和程序构建Crypto ++,您应该了解Visual Studio解决方案中有多个项目。当您说“添加了所有头文件和源文件” 时,您同时添加了库(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